mapa={ name=nil, w=128, h=128, surface=nil, new = function(w,h) mapa.name=nil mapa.w,mapa.h=w,h if mapa.surface~=nil then freesurf(mapa.surface) end mapa.surface=newsurf(w,h) setmap(mapa.surface) for y=0,127 do for x=0,127 do mset(x,y,0) end end end, load = function(filename) file = io.open("data/"..filename, "r") if file then io.input(file) mapa.w = io.read() mapa.h = 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 mset(x,y,m) x=x+1 end end io.close(file) end end, save = function(filename) mapa.name=filename if file then file = io.open("data/"..filename, "w") io.output(file) io.write(mapa.w.."\n") io.write(mapa.h.."\n") for y=0,mapa.h-1 do for x=0,mapa.w-1 do io.write(mget(x,y)..",") end io.write("\n") end io.close(file) end end }