pico-8 cartridge // http://www.pico-8.com version 42 __lua__ function _init() initmap() end function _update() updateplayer() if btnp(❎) then reload() _init() end end function _draw() cls() camera(-20,-20) map() drawboxes() drawplayer() end -->8 function initmap() m={ w=8, h=8, wallmap={}, boxmap={} } boxes={} box_i=1 box_number={[5]=1,[21]=2} --number on box player={ x=0, --position y=0, dir=1, --1 right 2 left 3 down 4 up image={3,4,19,35} } ---map for i=0,m.w-1 do m.wallmap[i]={} m.boxmap[i]={} for j=0,m.h-1 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), number=0 } box.number=box_number[box.image] boxes[box_i]=box m.boxmap[i][j]=box_i box_i+=1 mset(i,j,17) end end end end end function drawboxes() for b in all(boxes) do spr(b.image,b.x*8,b.y*8) end end -->8 function updateplayer() 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) 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 --box + push elseif m.boxmap[player.x+dx][player.y+dy]!=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 end end function drawplayer() spr(player.image[player.dir],player.x*8,player.y*8) end __gfx__ 0000000033333333554994550111111001111110feeeeeee00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000003b3333335444944501ffff1001ffff10ffe11eef00000000000000000000000000000000000000000000000000000000000000000000000000000000 0070070033b333333499994301f0f010010f0f10fffe1eff00000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000333333335449444511ffef0001feff11ffff1fff00000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000333333335499994501999a9999a99910fffe1fff00000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700333333b35444944300aaaa0000aaaa00ffee1fff00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000033333b335499994500aaaa0000aaaa00fee111ff00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000033333333554944550090090000900900eeeeeeef00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000033333333535555550111111000000000feeeeeee00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000333333335444444501ffff1000000000ff1111ef00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000003333333349494944010ff01000000000fffee1ff00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000333333b39949994911feef1100000000ffffe1ff00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000003333333349994999009aa90000000000ff1111ff00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000003b33333349494944009aa90000000000ff1eefff00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000333333335444444500aaaa0000000000fe1111ff00000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000033333333553553550090090000000000eeeeeeef00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000555535555544945301111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000344944453449944501111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000549949434499494401111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000549499959449999911111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000599494459999494909111190000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000549999454494494409aaaa90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000544494455449944500aaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000355355555349445500900900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __gff__ 0001020404080000000000000000000000010204000800000000000000000000000202040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __map__ 2212121212121212220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0201011101011101020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0211210101151111020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0201111111020111020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0211050112220111020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0201011111110112220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0211112101030111020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0211010111111101020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 2212121212121212220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000