diff --git a/data/editor.lua b/data/editor.lua index 5291e80..b6cf42c 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -24,9 +24,39 @@ editor = { editor.oy = 0 end, + load = function(level) + local base_name = "level" .. tostring(level) + local file = io.open("data/" .. base_name .. ".lev", "r") + if file then + for line in file:lines() do + local key,value = line:match("^(.+)=(.+)$") + if key and value then + if key == "start-x" then + editor.ox = tonumber(value) + elseif key == "start-y" then + editor.oy = tonumber(value) + end + end + end + editor.num = level + surf.free(editor.map_surf[1]) + surf.free(editor.map_surf[2]) + editor.map_surf[1] = surf.load(base_name .. "_1.gif") + editor.map_surf[2] = surf.load(base_name .. "_2.gif") + else + print("No s'ha trobat l'arxiu!") + end + end, + save = function() - local base_name = "level" + tostring(editor.num) - + local base_name = "level" .. tostring(editor.num) + local file = io.open("data/" .. base_name .. ".lev", "w") + if file then + file:write("start-x=" .. tostring(editor.ox) .. "\n") + file:write("start-y=" .. tostring(editor.oy) .. "\n") + end + surf.save(editor.map_surf[1], "data/" .. base_name .. "_1.gif") + surf.save(editor.map_surf[2], "data/" .. base_name .. "_2.gif") end, update = function() @@ -63,6 +93,10 @@ editor = { editor.current_layer=2 elseif key.press(key.F) then editor.fill(tx//8, ty//8, map.tile(mx/8, my/8)) + elseif key.down(key.LCTRL) and key.press(key.S) then + editor.save() + elseif key.down(key.LCTRL) and key.press(key.L) then + editor.load(1) end if mouse.down(mouse.LEFT) then diff --git a/data/level1.lev b/data/level1.lev new file mode 100644 index 0000000..99f6b1c --- /dev/null +++ b/data/level1.lev @@ -0,0 +1,2 @@ +start-x=-24 +start-y=-24 diff --git a/data/level1_1.gif b/data/level1_1.gif new file mode 100644 index 0000000..c29b3da Binary files /dev/null and b/data/level1_1.gif differ diff --git a/data/level1_2.gif b/data/level1_2.gif new file mode 100644 index 0000000..27f3b88 Binary files /dev/null and b/data/level1_2.gif differ