levels={} game={ cam={x=0,y=0}, restart=function() flags={} objects.list={} actors.main={name="jailer",x=40,y=26,o="r",gfx={x=32,y=0},level="arq"} game.init("arq") end, init=function(levelname,f,objs) if f then flags=f end if objs then objects.list=objs end game.level=levelname actors.init() if actors.main.level==levelname then actors.add({name=actors.main.name,x=actors.main.x,y=actors.main.y,o=actors.main.o,gfx=actors.main.gfx}) end levels[game.level].load() if game.paused then game.resume() else update=game.update end actors.sort() fade.fadein() end, show_menu=function() game.pause() menu.show({ {"GUARDAR PARTIDA", game.save}, {"CARREGAR PARTIDA", game.load}, {"EIXIR", main_init}, }, game.resume) end, save=function() local i=1 file = io.open(configfolder().."slot"..i..".txt", "w") if file then io.output(file) io.write("level="..game.level.."\n") local hero = actors.search(actors.main.name) io.write("x="..hero.x.."\n") io.write("y="..hero.y.."\n") io.write("o="..hero.o.."\n") io.write("[FLAGS]\n") for k,v in pairs(flags) do io.write(k.."="..v.."\n") end io.write("[OBJECTS]\n") for i,v in ipairs(objects.list) do io.write(v.."\n") end io.close(file) end game.resume() end, load=function() local i=1 file = io.open(configfolder().."slot"..i..".txt", "r") local level_name = "" local new_flags={} local new_objects={} if file then io.input(file) local k,v=getkeyval(io.read()) level_name=v local k,v=getkeyval(io.read()) actors.main.x=tonumber(v) local k,v=getkeyval(io.read()) actors.main.y=tonumber(v) local k,v=getkeyval(io.read()) actors.main.o=v io.read() -- ignore "[FLAGS]" line local line = io.read() while line ~= "[OBJECTS]" do local k,v=getkeyval(line) new_flags[k]=v line = io.read() end line = io.read() while line do table.insert(new_objects, line) line = io.read() end io.close(file) end fade.fadeout() --game.resume() --actors.main.x=10 --actors.main.y=8 game.init(level_name,new_flags,new_objects) end, update=function() if game.paused then return end local hero = actors.search("jailer") if hero then game.cam.x = hero.x*8 + hero.dx*2 - 80 if game.cam.x+160 > mapa.w*8 then game.cam.x = mapa.w*8-160 end if game.cam.x < 0 then game.cam.x=0 end game.cam.y = hero.y*8 + hero.dy*2 - 72 if game.cam.y+144 > mapa.h*8 then game.cam.y = mapa.h*8-144 end if game.cam.y < 0 then game.cam.y=0 end end cls(6) camera(game.cam.x, game.cam.y) setsource(tiles) setmap(mapa.surface) map(0,0,0,0,mapa.w, mapa.h) setsource(sprites) actors.draw() if mapa.front_layer then setsource(tiles) setmap(mapa.front_layer) map(0,0,0,0,mapa.w, mapa.h) end setmap(mapa.surface) camera(0,0) text(tostring(game.cam.x)..","..tostring(game.cam.y),1,1,8) if not scene.script and hero and not hero.path and hero.dx+hero.dy==0 then if btn(KEY_DOWN) then hero.path={pos=0,route='d',keys=true} elseif btn(KEY_UP) then hero.path={pos=0,route='u',keys=true} elseif btn(KEY_LEFT) then hero.path={pos=0,route='l',keys=true} elseif btn(KEY_RIGHT) then hero.path={pos=0,route='r',keys=true} elseif btnp(KEY_SPACE) then actors.interact(hero.x,hero.y,hero.o) end end if btnp(KEY_ESCAPE) then game.show_menu() end if beat() then actors.update() end end, pause=function() game.paused = true rectfill(9,84, 150, 128,6) rect(9,84, 150, 128,8) rect(8,83, 151, 129,6) text("OBJECTES:",14,82,8) setsource(objectes) local x,y=15,90 for i,name in ipairs(objects.list) do local obj = object[name] sspr(obj.x,obj.y,16,16,x,y) x=x+19 if x==148 then x,y=15,y+19 end end end, resume=function() game.paused = nil end }