pico-8 cartridge // http://www.pico-8.com version 42 __lua__ --2bitspritesheet v0.1 --@shiftalow / bitchunk --knutil_0.14.0 --set1:basic --function amid(...) --end function bpack(w,s,b,...) return b and flr(0x.ffff<>>s|bpack(w,s-w[#w],...) or 0 end function bunpack(b,s,w,...) if w then return flr(0x.ffff<(d or 0) do v=sub(v,2) end return v end function ttable(p) return count(p) and p end --set2:objects --exrect cat(_ENV,htblp[[ _mkrs{x y w h ex ey r p} _hovk{{x y}{x ey}{ex y}{ex ey}} _mnb{cam con hov ud rs rf os of cs cf} ]]) function _rfmt(p) local x,y,w,h=unpack(ttable(p) or split(p,' ',true)) return comb(_mkrs,{x,y,w,h,x+w-mid(w,1,-1),y+h-mid(h,1,-1),w/2,p}) end function exrect(p) local o=_rfmt(p) return cat(o,comb(_mnb,{ {x=0,y=0} ,function(p,y) if y then return inrng(p,o.x,o.ex) and inrng(y,o.y,o.ey) else return o.con(p.x,p.y) and o.con(p.ex,p.ey) end end ,function(r,i) local h for i,v in pairs(_hovk) do h=h or o.con(r[v[1]],r[v[2]]) end return h or i==nil and r.hov(o,true) end ,function(p,y,w,h) return cat( o,_rfmt((tonum(p) or not p) and {p or o.x,y or o.y,w or o.w,h or o.h} or p )) end ,function(col,f) local c=o.cam f=(f or rect)(o.x-c.x,o.y-c.y,o.ex-c.x,o.ey-c.y,col) return o end ,function(col) return o.rs(col,rectfill) end })) end --scenes _odkey=msplit'_rate _cnt _rm _fst _lst _nm _dur _prm' function scorder(...) local o={} return cat(o,comb(_odkey,{ function(d,r,c) local f,t=unpack(ttable(d) or msplit(d)) r=r or _dur return min(c or _cnt,r)/max(r,1)*(t-f)+f end ,0,false,true,false ,... })) end _scal={} function mkscenes(keys) return tmap(ttable(keys) or msplit(keys),function(v) local o={} _scal[v]=cat(o,comb(msplit'ps st rm cl fi cu us env tra ords nm',{ function(...) return add(o.ords,scorder(...)) end ,function(...) o.cl() return o.ps(...) end ,function(s) s=s and o.fi(s) or not s and o.cu() if s then del(o.ords,s)._rm=true end return s end ,function() local s={} while add(s,o.rm()) do end return s end ,function(key) for v in all(o.ords) do if v._nm==key or key==v then return v end end end ,function(n) return o.ords[n or 1] end ,function(...) return add(o.ords,scorder(...),1) end ,function(c) foreach(_odkey,function(v) _ENV[v],c[v]=c[v],_ENV[v] end) return c end ,function(n) local c=ttable(n) or o.cu(n) if c then o.env(c) _cnt+=1 _cnt,_fst,_lst=_cnt==0x7fff and 1 or _cnt,_cnt==1,inrng(_dur,1,_cnt) if _rm or _nm and _ENV[_nm] and _ENV[_nm](c) or _lst then o.rm(o.env(c)) else o.env(c) end end end ,{},v })) return o end) end function scmd(b,p,...) p=p or {} return tmap(msplit(replace(b,"\t",""),"\n",' '),function(v) local s,m,f,d=unpack(v) return s=='' and 'eoc' or _scal[s] and _scal[s][m](f,tonum(d),p) or false end) ,... and scmd(...) end cmdscenes=scmd function transition(v) v.tra() end -->8 --input function getinput() tmap(btnc,function(v,i) local s=not scans[i] and btn(i) or stat(28,scans[i])==true btns[i],v=s,s and v+1 or 0 butrg[i],btnc[i],btrg[i],btp[i] =v0,mb&2>0,mb&4>0 ,w ,_most.stx,_most.sty ,_most.lh,_most.rh,_most.mh ,_mo and _mo.x~=x ,_mo and _mo.y~=y }) tmap(_mobtn,function(k) local k,t,ut,h,db=unpack(k) if _mo[k] then _most[k]+=1 _mo[ut]=false else _mo[ut],_most[k]=_most[k]>0,0 end _mo[t]=_most[k]==1 _most[h]=max(0,_most[h]-1) if _mo[t] then _mo[db]=_most[h]>0 _most[h]=_mo[db] and 0 or 12 end end) if ambtn() then _most.stx,_most.sty=_mo.x,_mo.y end _mo.sx,_mo.sy=_most.stx,_most.sty _mo.mv=(_mo.x~=_most.x) or (_mo.y~=_most.y) _most.x,_most.y=_mo.x,_mo.y _mx,_my=_mo.x,_mo.y _mo.ex,_mo.ey=_mx,_my --is contain for rect _amb,_mlt,_mrt,_mmt=ambtn() _mlu,_mru,_mmu ,_ml,_mr,_mm,_mw,_ismw= _mo.lut,_mo.rut,_mo.mut ,_mo.l,_mo.r,_mo.m,_mo.w,_mo.w~=0 end -->8 --set3:debugging --dmp function dmp(v,q,s) poke(0x5f58,0) if not s then q,s,_dmpx,_dmpy="\f6","\n",0,-1 end local p,t=s tmap(ttable(v) or {v},function(str,i) t=type(str) if ttable(str) then q,p=dmp(str,q..s..i.."{",s.." ")..s.."\f6}",s else q..=join('',p,i ,comb(msplit"number string boolean function nil" ,msplit"\ff#\f6:\ff \fc$\f6:\fc \fe%\f6:\fe \fb*\f6:\fb \f2!\f6:\f2" )[t],tostr(str),"\f6 ") p="" end end) q..=t and "" or s.."\f2!\f6:\f2nil" ::dmp:: _update_buttons() if s=="\n" and not btnp'5' then flip() cls() ?q,_dmpx*4,_dmpy*6 _dmpx+=_kd'0'-_kd'1' _dmpy+=_kd'2'-_kd'3' goto dmp end return q end function _kd(d) return tonum(btn(d)) end --dbg function dbg(...) local p,d={},{...} for i=1,#d do if add(p,tostr(d[i]))=='d?' then poke(0x5f58,0) tmap(_dbgv,function(v,i) oprint(join(' ',unpack(v)),0,0+i*8,0,7) end) _dbgv,p={} end end add(_dbgv,p,1) end dbg'd?' -->8 function _init() cx,cy=0,0 end function _update60() --if _mmu then getmouse() if _mmt then csx,csy=_mo.x+cx,_mo.y+cy end if _mm then cx,cy=csx-_mo.x,csy-_mo.y end --if _mmu then ----stop() ----cx,cy=_mo.x,_mo.y --end --dbg(_mo.sx,cy) end function _draw() cls(1) --rect(16,48,56,88,6) -- --?'x1:y1',10,40 --?'x2:y2',44,92 -- --rect(70,48,110,88,6) -- --?'x2:y2',64,40,9 --?'x1:y1',98,92 -- --return camera(cx,cy) rectfill(-1,-1,256,128,0) rect(-1,-1,256,128,13) spr(0,1,0,0,16,16) spr(0x100,2,128,0,16,16) --spr(0x200,3,0,256,16,16) --spr(0x300,4,256,256,16,16) camera() ?"\^x8\^y8\f1\^.>Aやしコm2、\n\^g\f7\^.\0>BB\"□\f\0\n",_mx,_my pal() dbg'd?' end -->8 cat(_ENV,tmap(htblp[[ spal{1 0123456789abcdef$ 0567000005670000$ 0000156700001567$ } ]],function(v) return {mkpal(unpack(v))} end)) --dmp(spal) spr,_spr=function(n,c,...) local p={peek(0x5f00,16)} pal(spal[n\0x100+1]) _spr(sgn(n)*n%256,...) poke(0x5f00,unpack(p)) end,spr __gfx__ 0000000000ffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000ffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0070070000ffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0007700000ffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0007700000ffff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000444444440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000444444440505550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000111111110505050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000111111110500050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000044444400555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000044444400005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000111111110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000