241 lines
7.0 KiB
Lua
241 lines
7.0 KiB
Lua
require "actors"
|
|
require "menu"
|
|
require "objects"
|
|
require "scene"
|
|
require "wait"
|
|
require "switches"
|
|
require "brymode"
|
|
|
|
levels={}
|
|
|
|
require "m_arq"
|
|
require "m_jail1"
|
|
require "m_prac1"
|
|
require "m_prac2"
|
|
require "m_prac3"
|
|
require "m_repro"
|
|
require "m_vella"
|
|
require "m_exterior"
|
|
require "m_eui"
|
|
|
|
game={
|
|
cam={x=0,y=0},
|
|
|
|
restart=function()
|
|
flags={}
|
|
objects.list={}
|
|
--actors.main={name="jailer",x=43,y=25,o="u",gfx={x=32,y=0},level="vella"}
|
|
--game.init("vella")
|
|
actors.main={name="jailer",x=12,y=12,o="r",gfx={x=32,y=0},level="arq"}
|
|
game.init("arq")
|
|
end,
|
|
|
|
startfromeditor=function(s_level, s_x, s_y)
|
|
flags={}
|
|
objects.list={}
|
|
actors.main={name="jailer",x=s_x,y=s_y,o="d",gfx={x=32,y=0},level=s_level}
|
|
game.init(s_level)
|
|
--actors.main={name="jailer",x=8,y=12,o="l",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()
|
|
switches.reset()
|
|
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 not game.paused then
|
|
update=game.update
|
|
end
|
|
game.resume()
|
|
actors.sort()
|
|
if levels[game.level].init_scene then
|
|
if not flags.escena_inicial then
|
|
game.update()
|
|
levels[game.level].init_scene()
|
|
end
|
|
end
|
|
fade.fadein()
|
|
end,
|
|
|
|
show_menu=function()
|
|
game.pause()
|
|
--brymode.show(game.resume)
|
|
menu.show({ {"GUARDAR PARTIDA", game.save},
|
|
{"CARREGAR PARTIDA", game.load},
|
|
{"EIXIR", main_init},
|
|
}, game.resume)
|
|
end,
|
|
|
|
show_debug_menu=function()
|
|
game.pause()
|
|
menu.show({ {"EDIT FROM HERE", editor.editfrom},
|
|
{"CARREGAR PARTIDA", game.load},
|
|
{"EIXIR", main_init},
|
|
}, game.resume)
|
|
end,
|
|
|
|
save=function()
|
|
local i=1
|
|
file = io.open(config.folder().."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(config.folder().."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
|
|
local ignore = 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,
|
|
|
|
draw=function()
|
|
surf.cls(6)
|
|
view.origin(-game.cam.x, -game.cam.y)
|
|
surf.source(tiles)
|
|
map.surf(mapa.surface)
|
|
map.draw()--map(0,0,0,0,mapa.w, mapa.h)
|
|
switches.draw();
|
|
surf.source(sprites)
|
|
if key.down(key.LSHIFT) then pal.subpal(1,16,8) end
|
|
actors.display()
|
|
pal.subpal()
|
|
local mx,my=mouse.pos()
|
|
if actors.under_cursor~="" then
|
|
if (mx<=80) then
|
|
text(actors.under_cursor,mx+game.cam.x+4,my+game.cam.y+4,9)
|
|
else
|
|
local size = #actors.under_cursor
|
|
text(actors.under_cursor,mx+game.cam.x-size*4,my+game.cam.y+4,9)
|
|
end
|
|
end
|
|
if mapa.front_layer then
|
|
surf.source(tiles)
|
|
map.surf(mapa.front_layer)
|
|
map.draw() -- map(0,0,0,0,mapa.w, mapa.h)
|
|
end
|
|
map.surf(mapa.surface)
|
|
view.origin(0,0)
|
|
for i=0,15 do draw.rectf(20+i*4,0,4,4,i) end
|
|
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
|
|
|
|
game.draw()
|
|
|
|
local mx,my=mouse.pos()
|
|
text(math.floor((mx+game.cam.x)/8)..","..math.floor((my+game.cam.y)/8),1,19,8)
|
|
|
|
text(game.cam.x..","..game.cam.y,1,1,8)
|
|
if hero then
|
|
text(hero.x..","..hero.y,1,7,8)
|
|
end
|
|
text(game.level,1,13,8)
|
|
|
|
if not scene.script and hero and not hero.path and hero.dx+hero.dy==0 then
|
|
if key.down(key.DOWN) then
|
|
hero.path={pos=0,route='d',keys=true}
|
|
elseif key.down(key.UP) then
|
|
hero.path={pos=0,route='u',keys=true}
|
|
elseif key.down(key.LEFT) then
|
|
hero.path={pos=0,route='l',keys=true}
|
|
elseif key.down(key.RIGHT) then
|
|
hero.path={pos=0,route='r',keys=true}
|
|
elseif key.press(key.SPACE) then
|
|
actors.interact(hero.x,hero.y,hero.o)
|
|
end
|
|
end
|
|
if key.press(key.ESCAPE) then
|
|
game.show_menu()
|
|
elseif key.press(key.TAB) then
|
|
game.show_debug_menu()
|
|
end
|
|
|
|
if sys.beat() then actors.update() end
|
|
end,
|
|
|
|
pause=function()
|
|
game.paused = true
|
|
draw.rectf(9,84, 141, 44,6)
|
|
draw.rect(9,84, 141, 44,8)
|
|
draw.rect(8,83, 143, 46,6)
|
|
text("OBJECTES:",14,82,8)
|
|
surf.source(objectes)
|
|
|
|
local x,y=15,90
|
|
for i,name in ipairs(objects.list) do
|
|
local obj = object[name]
|
|
draw.surf(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
|
|
} |