

' by Atomose Studio 2022

NOMAINWIN

DIM sintable(360), costable(360), map$(20), color$(10)

color$(1)="blue"
color$(2)="green"
color$(3)="darkgray"
color$(4)="darkred"
color$(5)="darkgray"
color$(6)="darkpink"
color$(7)="blue"
color$(8)="darkblue"
color$(9)="darkgray"
color$(10)="lightgray"

map$(1)  = "53535353535353535353535353"
map$(2)  = "32000000000090000000000005"
map$(3)  = "50000900000000000009000003"
map$(4)  = "30000000090000900000000005"
map$(5)  = "50090000000000000000000093"
map$(6)  = "30000000003535353000000905"
map$(7)  = "50900000905333335000000003"
map$(8)  = "30009000003333333000000005"
map$(9)  = "50000000005333335000900003"
map$(10) = "30000000003333333000000005"
map$(11) = "50000090005333335009000003"
map$(12) = "30000000003333333000000005"
map$(13) = "50000009005333335000009003"
map$(14) = "30000001003333333000000005"
map$(15) = "50900000005353535000000003"
map$(16) = "30000000000090000000000005"
map$(17) = "50000900000000000009000003"
map$(18) = "30000000090000900000000005"
map$(19) = "50090000000000000000000093"
map$(20) = "35353535353535353535353535"

    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

WindowWidth=620 : WindowHeight=410 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
global dy,dx : posx=32 : posy=32 : angle=0
GRAPHICBOX #win.g, 5, 5, 595, 335
GRAPHICBOX #win.g2, 5, 343, 595, 25
OPEN "Open World 3D" FOR window AS #win
print #win, "trapclose [quit]"
PRINT #win.g2, "down; font Times New Roman 9; place 210 17 ;\"; "use ZQSD/WASD or arrows for moove"

[raycast]
scan
oldTime = time : time = time$("ms") : frameTime = (time - oldTime) / 1000 : fp$ = str$(int(1/frameTime)) : #win.g2, "place 10 17;\";"FPS : ";fp$;"    "

dy = 0 : dx = 0
call readJStick 1
select case dx
    case 1
        angle = angle + 3
    case -1
        angle = (angle + 357) mod 360
end select
select case dy
    case 1
        if (t-62)>0 then
        bx = posx - (sintable(((t-62) mod 360)) / 40)
        by = posy - (costable(((t-62) mod 360)) / 40)
        k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
        if k = 9 then notice "GAME OVER"
        if k = 2 then notice "VICTORY"
        IF k = 0 THEN
            posx = posx - (sintable(((t-62) mod 360)) / 40)
            posy = posy - (costable(((t-62) mod 360)) / 40)
        END IF
        end if
    case -1
        if (t-62)>0 then
        bx = posx + (sintable(((t-62) mod 360)) / 40)
        by = posy + (costable(((t-62) mod 360)) / 40)
        k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
        if k = 9 then notice "GAME OVER"
        if k = 2 then notice "VICTORY"
        IF k = 0 THEN
            posx = posx + (sintable(((t-62) mod 360)) / 40)
            posy = posy + (costable(((t-62) mod 360)) / 40)
        END IF
        end if
end select

FOR t = angle TO (angle + 119)
    oldK = k
    PRINT #win.g, "down"
    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 + 0.04 : k = ASC(MID$(map$(int(by/10)),int(bx/10),1))-48
    LOOP UNTIL (k > 1)
        x = (t - angle) * 4.978 : dd = (100 / l)
        PRINT #win.g, "color ";color$(k);"; backcolor ";color$(k);"; place ";x;" ";(100-dd);"; boxfilled ";(x+5);" ";(100+dd)
        PRINT #win.g, "color ";color$(10);"; backcolor ";color$(10)
        PRINT #win.g, "boxfilled ";(x+5);" 0";"; place ";x;" ";(100+dd)
        PRINT #win.g, "boxfilled ";(x+5);" 445";"; place ";x;" ";(100-dd)
        PRINT #win.g, "color black; goto ";(x+5);" ";(100-dd);"; place ";x;" ";(100+dd);"; goto ";(x+5);" ";(100+dd)
        if oldK <> k then print #win.g, "line "; x; " "; (100-dd); " "; x; " "; (100+dd)
    NEXT t
    PRINT #win.g, "up"
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(asc("Z")) or GetAsyncKeyState(_VK_UP)) AND (GetAsyncKeyState(asc("Q")) or GetAsyncKeyState(_VK_LEFT)) then dy = -1 : dx = -1 : goto [endPOINT]
        if (GetAsyncKeyState(asc("Z")) or GetAsyncKeyState(_VK_UP)) AND (GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT)) then dy = -1 : dx = 1 : goto [endPOINT]
        if (GetAsyncKeyState(asc("S")) or GetAsyncKeyState(_VK_DOWN)) AND (GetAsyncKeyState(asc("Q")) or GetAsyncKeyState(_VK_LEFT)) then dy = 1 : dx = 1 : goto [endPOINT]
        if (GetAsyncKeyState(asc("S")) or GetAsyncKeyState(_VK_DOWN)) AND (GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT)) then dy = 1 : dx = -1 : goto [endPOINT]
        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
        [endPOINT]
    end sub

    [quit]
    CLOSE #win : END

