--mapa={} tiletype={void=0,nonpc=1,stair=2,switch=3,half=4,block=5} mapa.wait=0 mapa.step=0 function mapa_do_backup() mapa_backup={} for i=1,#mapa do mapa_backup[i]={} for j=1,#mapa[i] do mapa_backup[i][j]=mapa[i][j] end end end function mapa_restore_backup() for i=1,#mapa do for j=1,#mapa[i] do mapa[i][j]=mapa_backup[i][j] end end end function mapa_new() for my=0,7 do for mx=0,9 do local mi=1+mx+my*10 mapa[mi]={} for ty=0,5 do for tx=0,11 do local tile=256 if mx==0 and tx==0 then tile=16 elseif mx==4 and tx==11 then tile=16 elseif ty==0 or ty==5 then if tx%2==0 then tile=20 else tile=21 end end mapa[mi][1+tx+ty*12]=tile end end end end end function mapa_save() file = io.open("data/map.lua", "w") io.output(file) io.write("mapa={\n") for i=1,80 do io.write(" -- "..i.."\n {\n ") for j=1,72 do io.write(mapa[i][j]..",") if j%12==0 then io.write("\n ") end end io.write("\n },\n") end io.write("}\n") io.close(file) end anim_tiles={113,114,112,116,117,115,119,120,118,122,121} function mapa_update(hab1,hab2) mapa.wait=mapa.wait+1 if mapa.wait==6 then mapa.wait=0 mapa.step=(mapa.step+1)&31 local hab=hab1 repeat for ty=0,5 do for tx=0,11 do local tile=mapa[1+hab][1+tx+ty*12] if tile>=112 and tile<126 then mapa[1+hab][1+tx+ty*12]=anim_tiles[tile-111] end end end if hab==hab2 then break end hab=hab2 until false end end function mapa_draw(hab) for ty=0,5 do for tx=0,11 do local tile=mapa[1+hab][1+tx+ty*12] if tile~=256 and (tile<126 or mapa.step>4) then sspr((tile&15)*8,64+(tile>>4)*8,8,8,tx*8,ty*8) end end end end function mapa_set_tile(hab,x,y,tile) mapa[1+hab][1+x+y*12]=tile end function mapa_set_tile_by_index(hab,index,tile) mapa[1+hab][index]=tile end function mapa_get_tile(hab,x,y) return mapa[1+hab][1+x+y*12] end function mapa_cycle_colors(hab) for i=1,72 do local tile=mapa[1+hab][i] if tile<4 then tile=(tile+1)&3 elseif tile>=16 and tile<48 then tile=tile+8 if tile>=48 then tile=tile-32 end end mapa[1+hab][i]=tile end end function check_tile(hab,x,y) local xx=min(11,max(0,flr(x/8))) local yy=min(5,max(0,flr(y/8))) --rect(xx*8,yy*8,xx*8+8,yy*8+8,3) local tile=mapa_get_tile(hab,xx,yy) if tile<8 then return tiletype.half elseif tile<15 then return tiletype.stair elseif tile==15 then return tiletype.switch elseif tile<64 then return tiletype.block elseif tile==111 then return tiletype.nonpc else return tiletype.void end end