LoginSignup
1
0

More than 5 years have passed since last update.

【TIC-80】 4tile to 2x2 simple Auto tile

Posted at

4タイルスプライトエディタ.gif
qiita.gif

4tile2x2auto.lua
-- title:  auto2x2tile
-- author: uokagi
-- desc:   4tiles to 2x2 simple auto tile
-- script: lua

W,H=240,136
U,D,L,R,LU,RU,LD,RD=1,2,3,4,5,6,7,8
AT={[0]={U,L,LU},{U,R,RU},{D,L,LD},{D,R,RD}}
OF={{{0,3},{1,1}},{{1,1},{2,2}}}
FN={[0]=1,0,3,2}

-- my function
rm2x2tile=function(t,x,y)
    if t==0 then return 0 end
    local fU=(t==mget(x%W,(y-2)%H))and 1 or 2
    local fD=(t==mget(x%W,(y+2)%H))and 1 or 2
    local fL=(t==mget((x-2)%W,y%H))and 1 or 2
    local fR=(t==mget((x+2)%W,y%H))and 1 or 2
    local fLU=(t==mget((x-2)%W,(y-2)%H))and 1 or 2
    local fRU=(t==mget((x+2)%W,(y-2)%H))and 1 or 2
    local fLD=(t==mget((x-2)%W,(y+2)%H))and 1 or 2
    local fRD=(t==mget((x+2)%W,(y+2)%H))and 1 or 2
    local an=x%2+y%2*2
    local fl={fU,fD,fL,fR,fLU,fRU,fLD,fRD}
    local vn,hn,sn=AT[an][1],AT[an][2],AT[an][3]
    local oid=OF[fl[vn]][fl[hn]][fl[sn]]
    if fl[vn]==2 and fl[hn]==1 then
        return t+oid*16,FN[an],1 end
    return t+oid*16,an end

testinit=function()
    chipset={0,1,2,3,4}
    i=1
end

testinit()
function TIC()
    cls(13)
    map(0,0,30,17,0,0,12,1,rm2x2tile)
    if btnp(4,1,20) then i=i%#chipset+1 end
    x,y,p=mouse()
    spr(256,x-x%16,y-y%16,0,2)
    idx=chipset[i]
    for j=0,3 do
        spr(idx+32,208+j%2*8,8+j//2*8,12,1,j)
    end 
    spr(257,208-4,8-4,12,3)
    if p then
        for j=0,3 do
            mset(x//16*2+j%2,y//16*2+j//2,idx) end end
    if btnp(5,1,20) then sync(0,0,true)end
end

前の8x8の簡易オートタイルのgif動画をtwitterで上げたら、外国の方から
「いいね」をもらってビビってます


TIC-80 は 8x8ドットのタイル単位で表示します。
remap はタイルIDの他に、flip(反転)、rotate(回転)も指定できます。

よって上下左右対称なら、

  1. 境界なし
  2. 一方向境界
  3. 二方向境界
  4. 斜めのみ境界

の4種類のタイルを用意しておけば、後は反転と回転で
16x16のシンプルなオートタイルなら実現が可能です。
タイルを組み合わせて保持しておく必要もないので
タイル領域の節約にもなります。

ただ、remap用の関数に割当てられるメモリが小さい(?)のか、
だらだら書いていたら正常に動作しなくなりました。
(ローカル変数の種類を減らしたら動くようになったり?)

対称ではないものは4x5の20必要だけど、これくらいなら大丈夫かなー、今度また作ってみよう。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0