Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
A jam submission

Mazemaker1kView game page

A simple raycaster made for #pico1k 2023!
Submitted by Soundole (@Soundole) — 1 hour, 8 minutes before the deadline
Add to collection

Play game

Mazemaker1k's itch.io page

Compressed Bytes used
1020

Source Code (OPTIONAL)
poke(0x5f2c,3)
rayangle=0.9722 --leftmost ray angle
locx=10.5 --player pos.
locy=10.5
md={} --map
md[0]={1,1,1,1,1,1,1,1,1,1,1,1}
md[1]={1,0,0,0,0,0,1,0,0,0,0,1}
md[2]={1,0,0,0,0,0,1,0,0,0,0,1}
md[3]={1,0,0,0,1,0,1,0,1,1,0,1}
md[4]={1,1,1,1,1,0,1,0,0,1,0,1}
md[5]={1,0,0,0,0,0,1,1,1,1,0,1}
md[6]={1,0,0,1,0,0,0,0,0,0,0,1}
md[7]={1,1,0,1,0,0,0,1,0,0,0,1}
md[8]={1,0,0,1,1,1,0,1,1,1,1,1}
md[9]={1,1,0,0,0,0,0,0,0,0,0,1}
md[10]={1,0,0,0,1,0,0,0,1,0,0,1}
md[11]={1,1,1,1,1,1,1,1,1,1,1,1}

for y=0,11 do
for x=1,12 do
mset(x+7,y+8,md[y][x])
end
end

function _update()

cls(12)
--stile:highlighted tile in front
stilex=flr(locx+2*cos(rayangle+0.0889))
stiley=flr(locy-2*sin(rayangle+0.0889))

for r=0,63 do --64 cast rays
--x/y component of ray direction
xratio=cos(rayangle+r*0.0028)
yratio=-sin(rayangle+r*0.0028)
nibble=0.1 --amount ray is extended each check
xcomp=0 --distances of ray tip from player
ycomp=0
dist=0.2 --distance from camera

while dist<16 do
--location collision tested
testx=locx+xcomp
testy=locy+ycomp
md=dist*cos((rayangle+0.0889)-(rayangle+r*0.0028)) --distance to player normal
--test,draw
if mget(testx,testy) == 1 then
line(r,32-32/md,r,32+32/md,5)
line(r,33-32/md,r,31+32/md,6)
break
else
--draw grass
grass=3
if (testx-flr(testx)<0.5) grass=11
--draw cursor
if flr(testx)==stilex and flr(testy)==stiley then
fillp(0x5a5a)
grass=178
end
line(r,32+32/md,r,30+32/md,grass)
fillp()
xcomp+=xratio*nibble
ycomp+=yratio*nibble
dist+=nibble
--longer ray nibble as distance goes up
if dist<1 then
nibble=0.05
elseif dist<2 then
nibble=0.1
elseif dist<3 then
nibble=0.3
elseif dist<5 then
nibble=0.5
else
nibble=0.7
end
end

end

end

if (btn(0)) rayangle-=0.01
if (btn(1)) rayangle+=0.01
cray=rayangle+0.0889 --centre ray
if btn(2) then
if mget(locx+cos(cray)/10,locy)!=1 then
locx+=cos(cray)/10
end
if mget(locx,locy-sin(cray)/10)!=1 then
locy-=sin(cray)/10
end
end
if btn(3) then
if mget(locx-cos(cray)/10,locy)!=1 then
locx-=cos(cray)/10
end
if mget(locx,locy+sin(cray)/10)!=1 then
locy+=sin(cray)/10
end
end
if btnp(4) then
--invert wall
place=mget(locx+2*cos(cray),locy-2*sin(cray))
if place==1 then
place=0
else
place=1
end
mset(locx+2*cos(cray),locy-2*sin(cray),place)
end

end

Leave a comment

Log in with itch.io to leave a comment.

Comments

Submitted(+1)

Loving the floor + tile placing indicator - great use of the raycaster algorithm for free UI!

Developer(+1)

Thank you! Glad you noticed it - one of those things that fillp makes super-easy to implement! :)

HostSubmitted(+1)

Really cool tech demo. I've still never learned how to do a raytracer - one of those on my TODO list.
Nice one! 👍

Developer(+1)

Thanks mate! I really appreciate this jam giving me the opportunity to try it out :)