Skip to content

Instantly share code, notes, and snippets.

@omgmog
Last active February 15, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omgmog/faf080f72f8991d895c17e550a319329 to your computer and use it in GitHub Desktop.
Save omgmog/faf080f72f8991d895c17e550a319329 to your computer and use it in GitHub Desktop.
Apply tiles from a tileset based on their neighbors
pico-8 cartridge // http://www.pico-8.com
version 16
__lua__
--init
_t=0
dirx={-1,1,0,0,1,1,-1,-1}
diry={0,0,-1,1,-1,1,1,-1}
tiles={16,8,15,7,12,4,11,3,14,6,13,5,10,2,9,0}
function _init()
_upd=upd_game
_drw=drw_game
end
-->8
--update
function _update()
_t+=1
_upd()
end
function upd_game()
if btnp(4) then
gen_bitwise()
end
if btnp(5) then
reload(0x2000,0x2000,0x1000)
end
end
function gen_bitwise()
for x=0,15 do
for y=0,15 do
local t,ct,nt = checktile(x,y),mget(x,y)
for i=1,#tiles do
if t < (i*16) then
nt=tiles[i]
break
end
end
if nt > 0 and ct > 0 then
mset(x,y,nt)
end
end
end
end
function checktile(x,y)
local sig,parity=0
for i=1,8 do
local dx,dy=x+dirx[i],y+diry[i]
local t=mget(dx,dy)
if t>0 then
parity=0
else
parity=1
end
sig=bor(sig,shl(parity,8-i))
end
return sig
end
-->8
--draw
function _draw()
_drw()
end
function drw_game()
cls(1)
map()
printo("z to generate bitwise tiles",5, 5)
printo("x to reset map",5,12)
end
-->8
--tools
function printo(str, x, y, c1, c2)
c1 = c1 or 7
c2 = c2 or 0
for i=-1,1 do
for j=-1,1 do
print(str,x+i,y+j,c2)
end
end
print(str,x,y,c1)
end
__gfx__
00000000888888888009900888888888000990088888888880099000888888880009900088888888800990088888888800099008888888888009900088888888
00000000800000088009900800000008000990088000000080099000000000000009900080000008800990080000000800099008800000008009900000000000
00700700800000088009900800000008000990088000000080099000000000000009900080000008800990080000000800099008800000008009900000000000
00077000800990088009900899999008999990088009999980099999999999999999999980099008800990089999900899999008800999998009999999999999
00077000800990088009900899999008999990088009999980099999999999999999999980099008800990089999900899999008800999998009999999999999
00700700800000088000000800000008000000088000000080000000000000000000000080099008800990080009900800099008800990008009900000099000
00000000800000088000000800000008000000088000000080000000000000000000000080099008800990080009900800099008800990008009900000099000
00000000888888888888888888888888888888888888888888888888888888888888888880099008800990080009900800099008800990008009900000099000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
99999999000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
99999999000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00099000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010100000001000101000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0101010100000101010101000001010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100010000000001000100000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100010000010101010101000101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0001010000010101000100000101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0001010100000100000000000100000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000100000101010100000101010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010001000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010001000000010101010001010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0101010101010101010101010001000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100010001000101010101010001000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0101010101010101010000010001000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010001000000010101010001000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010001000000000000000001010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
@omgmog
Copy link
Author

omgmog commented Feb 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment