Dungeon updates


This post will continue to be updated each time there are further edits!

Thanks to some tips from @Kamencesc and @pancelor in the comments, I was able to reduce the code even further. I added in a check that prevents the monsters from spawning on top of the cat when it starts a new level but currently there’s still an issue that monsters moves once before any player movement, so a new monster could walk onto the player on a newly spawned level. The monster movement was updated so they can only move in the 4 directions up down left right. No diagonals.

Code v5 on 2025-05-21

r,x,y,f=rnd,3,3,1::i::
e={}a=r(8)\1b=r(8)\1for i=1,5do repeat g=r(8)\1v=r(8)\1until g-x|v-y!=0e[i]={x=g,y=v}end::m::d=16for y=0,114,d do for x=0,114,d do
fillp(r(♥))rectfill(x,y,x+d,y+d,2)end end
?"▒",a*d+4,b*d+5,9
?"🐱",x*d+4,y*d+5
?f,2,2,6
for j in all(e)do
z=r(4)\1/4j.x+=cos(z)j.y+=sin(z)?"😐",j.x*d+4,j.y*d+5,8
if(j.x==x and j.y==y)stop()
if(x==a and y==b)f+=1goto i
end 
repeat
flip()v=btnp()until v>0
x+=v\2%2-v%2
y+=v\8%2-v\4%2goto m

Code v4 on 2025-05-17

r,x,y,f=rnd,3,3,1function _init()e={}a=r(8)\1b=r(8)\1for i=1,5do repeat g=r(8)\1v=r(8)\1until g-x|v-y!=0e[i]={x=g,y=v}end m()end
function _draw()v=btnp()if(v==2)x+=1m()
if(v==1)x-=1m()
if(v==4)y-=1m()
if(v==8)y+=1m()end function m()d=16for y=0,114,d do for x=0,114,d do
fillp(r(♥))rectfill(x,y,x+d,y+d,2)end end?"▒",a*d+4,b*d+5,9
?"🐱",x*d+4,y*d+5
?f,2,2,6
for j in all(e)do
z=r(4)\1/4
j.x+=cos(z)j.y+=sin(z)?"😐",j.x*d+4,j.y*d+5,8
if(j.x==x and j.y==y)stop()
if(x==a and y==b)f+=1_init()end end

Code v3 on 2025-05-16:

Third and perhaps final version of the code, where monsters shouldn’t spawn on the starting cat space, and score displayed in top left corner.

r,x,y,f=rnd,3,3,1function _init()
e={}a=r(8)\1b=r(8)\1
for i=1,5do repeat e[i]={x=r(8)\1,y=r(8)\1}until e[i].x!=x or e[i].y!=y end m()end
function _draw()v=btnp()
if(v==2)x+=1m()
if(v==1)x-=1m()
if(v==4)y-=1m()
if(v==8)y+=1m()end function m()d=16for y=0,114,d do for x=0,114,d do
fillp(r(♥))rectfill(x,y,x+d,y+d,2)end end
?"▒",a*d+4,b*d+5,9
?"🐱",x*d+4,y*d+5
?f,2,2,6
for j in all(e)do
j.x+=r(3)\1-1
j.y+=r(3)\1-1
?"😐",j.x*d+4,j.y*d+5,8
if(j.x==x and j.y==y)stop()
if(x==a and y==b)f+=1_init()
end end

code v2 on 2025-05-15:

On this version, I added checking so the monsters don’t spawn on the player but I also removed the score display from the top left corner in order to save a few characters. In this version the score is printed to the right of the cat. Maybe it’s the cat’s tail twisting into the shape of the score.

r,x,y,f=rnd,3,3,1function _init()
e={}a=r(8)\1b=r(8)\1
for i=1,5do repeat e[i]={x=r(8)\1,y=r(8)\1}until e[i].x!=x or e[i].y!=y end m()end
function _draw()v=btnp()
if(v==2)x+=1m()
if(v==1)x-=1m()
if(v==4)y-=1m()
if(v==8)y+=1m()end function m()d=16for y=0,114,d do for x=0,114,d do
fillp(r(9999))rectfill(x,y,x+d,y+d,2)end end
?"▒",a*d+4,b*d+5,9
?"🐱"..f,x*d+4,y*d+5
for j in all(e)do
j.x+=r(3)\1-1
j.y+=r(3)\1-1
?"😐",j.x*d+4,j.y*d+5,8
if(j.x==x and j.y==y)stop()
if(x==a and y==b)f+=1_init()
end end

code v1 on 2025-05-14:

The first version of the code. In this version, a monster could spawn on top of the cat.

r,x,y,f=rnd,3,3,1function _init()
e={}a=l()b=l()
for i=1,5do e[i]={x=l(),y=l()}end m()end
function _draw()v=btnp()
if(v==2)x+=1;m()
if(v==1)x-=1;m()
if(v==4)y-=1;m()
if(v==8)y+=1;m()end function m()c=114;d=16for y=0,c,d do for x=0,c,d do
fillp(r(9999))rectfill(x,y,x+d,y+d,2)end end
?"▒",a*d+4,b*d+5,9
?"🐱",x*d+4,y*d+5
?f,2,2,3
for j in all(e)do
j.x+=(r(3)-1)\1
j.y+=(r(3)-1)\1
?"😐",j.x*d+4,j.y*d+5,8
if(j.x==x and j.y==y)f=1;stop()
if(x==a and y==b)f+=1;_init()
end end function l()return r(8)\1end

Files

tweettweetdungeon.zip Play in browser
23 days ago

Leave a comment

Log in with itch.io to leave a comment.