mapa={ name=nil, w=128, h=128, surface=-1, new = function(w,h) mapa.name=nil mapa.w,mapa.h=w,h if mapa.surface~=-1 then surf.free(mapa.surface) end mapa.surface=surf.new(w,h) map.surf(mapa.surface) for y=0,127 do for x=0,127 do map.tile(x,y,0) end end mapa.front_layer=nil end, load = function(filename) file = io.open("data/"..filename, "r") if file then io.input(file) mapa.w = tonumber(io.read()) mapa.h = tonumber(io.read()) local num_layers=tonumber(io.read()) mapa.new(mapa.w, mapa.h) mapa.name=filename for y=0,mapa.h-1 do local line = io.read() local x=0 for m in string.gmatch(line, "%d+") do map.tile(x,y,m) x=x+1 end end if num_layers==2 then mapa.front_layer=surf.new(mapa.w,mapa.h) map.surf(mapa.front_layer) for y=0,mapa.h-1 do local line = io.read() local x=0 for m in string.gmatch(line, "%d+") do map.tile(x,y,m) x=x+1 end end end map.surf(mapa.surface) io.close(file) end end, save = function(filename) mapa.name=filename file = io.open("data/"..filename, "w") if file then io.output(file) io.write(mapa.w.."\n") io.write(mapa.h.."\n") if mapa.front_layer then io.write("2\n") else io.write("1\n") end map.surf(mapa.surface) for y=0,mapa.h-1 do for x=0,mapa.w-1 do io.write(map.tile(x,y)..",") end io.write("\n") end if mapa.front_layer then map.surf(mapa.front_layer) for y=0,mapa.h-1 do for x=0,mapa.w-1 do io.write(map.tile(x,y)..",") end io.write("\n") end end io.close(file) end end, check_collision=function(x,y) return map.tile(x,y) >= 32 or map.tile(x+1,y) >= 32 end }