I want to make my own raycaster game in picotron and I have been following this blog written for a pico-8 raycaster. I get an error when I run this and I am not sure what I should do to fix this issue. Help would be much appreciated.
Other than the code, all I did is make a sprite in slot 1 and draw a simple map in the map editor.
function _init() cam={ x=12, y=12, a=0, w2d=2 } scrx=0 end function _update() controls() end function _draw() cls() map(0,0,0,0,16,16) circ(cam.x,cam.y,2,12) --for scrx=0,480 do -- raycast(cam,scrx) --end raycast(cam,240) end function controls() if btn(0) then cam.a+=0.01 end if btn(1) then cam.a-=0.01 end if btn(2) then cam.x+=cos(cam.a)*0.5 cam.y+=sin(cam.a)*0.5 end if btn(3) then cam.x+=cos(cam.a)*-0.25 cam.y*=sin(cam.a)*-0.25 end end function raycast(cam,scrx) local rayvx,rayvy= cam.vx-cam.vy*cam.w2d*(scrx-64)/128, cam.vy+cam.vx*cam.w2d*(scrx-64)/128 -- distance traveled local dist=0 -- current coordinates local x,y=cam.x,cam.y -- map cel coordinate and value local celx,cely=x8,y8 local cel=mget(celx,cely) -- direction of ray local dirx,diry= sgn(rayvx),sgn(rayvy) -- distances across map cel local dist4x,dist4y= abs(8/rayvx), abs(8/rayvy) -- distances to next map cel local dx,dy= abs(4+4*dirx-x%8), abs(4+4*diry-y%8) local dist2x,dist2y= abs(dx/rayvx), abs(dy/rayvy) -- which direction / angle -- the wall was hit from local hita=0 -- perform dda repeat if dist2x=64 end |
I'm not home right now but I remember the error being about a missing "then" by the if statement at the end of the code. I'm not sure how that part of the code is supposed to work anyways
Ah yes...
That bit at the end looks very broken
Looks like the code's been cut off in that guide - a repeat statement should have an until part too. You might need to find another guide?
I suppose so. I sent an email to the author to see if they still have the code to share
If you view source on that webpage the full code is there. Here's the rest of it.
-- perform dda repeat if dist2x < dist2y then celx+=dirx dist+=dist2x dist2y-=dist2x dist2x=dist4x hita=0.25-dirx*0.25 else cely+=diry dist+=dist2y dist2x-=dist2y dist2y=dist4y hita=0.5+diry*0.25 end local cel=mget(celx,cely) if fget(cel,0) then -- ray hit a wall rect(celx*8,cely*8,celx*8+7,cely*8+7,12) else rect(celx*8+2,cely*8+2,celx*8+5,cely*8+5,11) end until dist >= 64 |
Oddly enough when I copied the code over here it got cut off in the same way as on the author's page. The problem was that they hadn't put a space between <
and dist2y
. So everything after dist2x
until =64
was being interpreted as an html tag that the browser didn't know how to render.
If you encounter more broken code @Nedim, just open up the page source and look for the code there. And if you feel like it pass that info along to the author in case they feel like fixing it.
[Please log in to post a comment]