pico-8 cartridge // http://www.pico-8.com version 42 __lua__ function _init() initmap() win=false hint=false timer=60 end function _update() updateplayer() check_win() if btnp(❎) then reload() _init() end end function _draw() cls() camera(-20,-20) map() drawboxes() drawplayer() if hint==true and timer>0 then timer-=1 print("can you hear it",10,25,7) end if win==true then rectfill(24,19,55,25,10) print("you win!",25,20,8) end end -->8 function initmap() m={ w=9, h=8, wallmap={}, boxmap={} } boxes={} box_i=1 box_words={ [5]="s",[6]="i", [21]="l",[22]="e", [37]="n",[38]="t" } --number on box box_target={"l","i","s","t","e","n"} player={ x=0, --position y=0, dir=1, --1 right 2 left 3 down 4 up image={3,4,19,35} } last_move={ x=0, y=0, b=0 } ---map for i=0,m.w do m.wallmap[i]={} m.boxmap[i]={} for j=0,m.h do m.boxmap[i][j]=0 local f=fget(mget(i,j)) if f==2 then m.wallmap[i][j]=1 --wall else m.wallmap[i][j]=0 --void ---player if f==4 then player.x=i player.y=j mset(i,j,17) ---boxes elseif f==8 then local box={ x0=i, y0=j, x=i, --position y=j, image=mget(i,j), letter=0 } box.letter=box_words[box.image] boxes[box_i]=box m.boxmap[i][j]=box_i box_i+=1 mset(i,j,17) end end end end end --new word order function check_win() local this_letter,next_letter local this_x,this_y=-1,-1 local next_x,next_y=-2,-2 local success=true for i=1,5 do this_letter=box_target[i] next_letter=box_target[i+1] for b in all(boxes) do if b.letter==this_letter then this_x=b.x this_y=b.y elseif b.letter==next_letter then next_x=b.x next_y=b.y end end if not(this_x+1==next_x and this_y==next_y) then success=false break end end win=success end function drawboxes() for b in all(boxes) do spr(b.image,b.x*8,b.y*8) end end -->8 function updateplayer() if hint==false then if btnp(➡️) or btnp(⬅️) or btnp(⬇️) or btnp(⬆️) then hint=true end else if btnp(➡️) then player.dir=1 try_move(1,0) elseif btnp(⬅️) then player.dir=2 try_move(-1,0) elseif btnp(⬇️) then player.dir=3 try_move(0,1) elseif btnp(⬆️) then player.dir=4 try_move(0,-1) elseif btnp(🅾️) then undo() end end end function try_move(dx,dy) --void + move if m.boxmap[player.x+dx][player.y+dy]==0 and m.wallmap[player.x+dx][player.y+dy]==0 then player.x+=dx player.y+=dy last_move.x=dx last_move.y=dy last_move.b=0 --box + push elseif inbounds(player.x+dx*2,player.y+dy*2)==true then if m.boxmap[player.x+dx][player.y+dy]!=0 and m.boxmap[player.x+dx*2][player.y+dy*2]==0 and m.wallmap[player.x+dx*2][player.y+dy*2]==0 then --box update local bi=m.boxmap[player.x+dx][player.y+dy] m.boxmap[player.x+dx][player.y+dy]=0 m.boxmap[player.x+dx*2][player.y+dy*2]=bi boxes[bi].x+=dx boxes[bi].y+=dy player.x+=dx player.y+=dy last_move.x=dx last_move.y=dy last_move.b=bi end end end function undo() local lx=last_move.x local ly=last_move.y local bi=last_move.b player.x-=lx player.y-=ly --box undo if bi>0 then m.boxmap[boxes[bi].x][boxes[bi].y]=0 boxes[bi].x-=lx boxes[bi].y-=ly m.boxmap[boxes[bi].x][boxes[bi].y]=bi end last_move={ x=0, y=0, b=0 } end function inbounds(x,y) if x>=0 and x=0 and y