From 5091fe267b01b57f4cf7b5911efba6dadf84155c Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 2 Feb 2023 18:54:40 +0100 Subject: [PATCH] - Implementat el segon layer - Implementat resizar el mapa --- data/editor.lua | 69 +++++++++++++++++++++++++++++++++++++++++++++--- data/game.lua | 11 ++++++-- data/jail.map | 39 +++++++++++++++++++++++++++ data/mapa.lua | 28 ++++++++++++++++++++ data/test.map | 1 + data/tiles.gif | Bin 1578 -> 1668 bytes 6 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 data/jail.map diff --git a/data/editor.lua b/data/editor.lua index 1b61c28..b90a003 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -15,12 +15,56 @@ editor={ menu.show({ {"NEW MAP", editor.new}, {"LOAD MAP", function() textbox.show("FILENAME TO LOAD:",editor.load, mapa.name) end}, {"SAVE MAP", function() if mapa.name~=nil then editor.save(mapa.name) else textbox.show("FILENAME TO SAVE:",editor.save, mapa.name) end end}, --- {"BACK TO EDITOR", function() editor.paused=false end}, + {mapa.front_layer and "DISABLE FRONT LAYER" or "ENABLE FRONT LAYER", editor.toggle_front_layer}, + {"RESIZE MAP", editor.resize}, {"EXIT", main_init}, --- {"ENNER LLOR NEIM", function() textbox.show("PELANDRUSC!") end} }, function()editor.paused=false end) end, + toggle_front_layer=function() + if not mapa.front_layer then + mapa.front_layer=newsurf(mapa.w,mapa.h) + editor.editing_front_layer=true + setmap(mapa.front_layer) + for y=0,mapa.h-1 do + for x=0,mapa.w-1 do + mset(x,y,0) + end + end + else + mapa.front_layer=nil + end + editor.paused=false + end, + + resize=function() + textbox.show("NEW MAP WIDTH:",function(value) + editor.new_w=value + textbox.show("NEW MAP HEIGHT:", function(value) + editor.new_h=value + editor.do_resize() + end, tostring(mapa.h)) + end, tostring(mapa.w)) + end, + + do_resize=function() + local old_surface= mapa.surface + mapa.w=tonumber(editor.new_w) + mapa.h=tonumber(editor.new_h) + mapa.surface=newsurf(mapa.w,mapa.h) + for y=0,mapa.h-1 do + for x=0,mapa.w-1 do + setmap(old_surface) + local value=mget(x,y) + setmap(mapa.surface) + mset(x,y,value) + end + end + freesurf(old_surface) + setmap(mapa.surface) + editor.paused=false + end, + floodfill=function(x,y,tile) local t=mget(x,y) mset(x,y,tile) @@ -92,8 +136,18 @@ editor={ cls() camera(editor.cam.x, editor.cam.y) setsource(tiles) + setmap(mapa.surface) map(0,0,0,0,mapa.w, mapa.h) - + if mapa.front_layer then + setmap(mapa.front_layer) + map(0,0,0,0,mapa.w, mapa.h) + end + if editor.editing_front_layer then + setmap(mapa.front_layer) + text("EDITING FRONT LAYER",12,2,10) + else + setmap(mapa.surface) + end local mx,my=mousex()+editor.cam.x,mousey()+editor.cam.y local tx,ty=mx>>3,my>>3 local rx,ry=tx<<3,ty<<3 @@ -149,6 +203,13 @@ editor={ if btnp(KEY_F) then editor.floodfill(tx,ty,editor.brush.tiles[1]) end + if btnp(KEY_1) then + if editor.editing_front_layer then + editor.editing_front_layer=nil + else + editor.editing_front_layer=true + end + end if btnp(KEY_RETURN) then editor.brush.tiles[1]=mget(tx,ty) end @@ -188,6 +249,7 @@ editor={ new=function() mapa.new(128,128) + editor.editing_front_layer=nil editor.paused=false end, @@ -198,6 +260,7 @@ editor={ load=function(filename) mapa.load(filename) + editor.editing_front_layer=nil editor.paused=false end } diff --git a/data/game.lua b/data/game.lua index fa8aa69..ddc485f 100644 --- a/data/game.lua +++ b/data/game.lua @@ -4,8 +4,8 @@ game={ restart=function() flags={} objects.list={} - actors.main={name="jailer",x=6,y=9,o="r",gfx={x=32,y=0},level="test"} - game.init("test") + actors.main={name="jailer",x=6,y=9,o="r",gfx={x=32,y=0},level="jail"} + game.init("jail") end, init=function(levelname,f,objs) @@ -133,9 +133,16 @@ game={ end 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) if not scene.script and hero and not hero.path and hero.dx+hero.dy==0 then diff --git a/data/jail.map b/data/jail.map new file mode 100644 index 0000000..d152bb9 --- /dev/null +++ b/data/jail.map @@ -0,0 +1,39 @@ +20 +18 +2 +17,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,27,17, +17,16,23,24,23,24,23,24,23,24,23,24,23,24,23,24,23,24,18,17, +17,16,39,40,39,40,39,40,39,40,39,40,39,40,39,40,39,40,18,17, +17,16,55,56,55,56,55,56,55,56,55,56,55,56,55,56,55,56,18,17, +17,16,10,11,12,13,5,2,10,11,12,13,5,2,10,11,12,13,18,17, +17,16,87,88,89,90,5,2,87,88,89,90,5,2,87,88,89,90,18,17, +17,16,10,11,12,13,5,2,10,11,12,13,5,2,10,11,12,13,18,17, +17,16,87,88,89,90,5,2,87,88,89,90,5,2,64,65,66,65,18,17, +17,16,10,11,12,13,5,2,10,11,12,13,5,2,80,81,82,81,18,17, +17,16,87,88,89,90,5,2,87,88,89,90,5,2,96,97,97,98,18,17, +17,16,10,11,12,13,5,2,10,11,12,13,5,2,5,2,5,3,18,17, +17,16,87,88,89,90,5,2,87,88,89,90,5,2,5,2,5,2,18,17, +17,16,10,11,12,13,5,2,10,11,12,13,5,2,5,2,5,2,18,17, +17,16,87,88,89,90,5,2,87,88,89,90,5,2,5,2,5,2,18,17, +17,16,5,2,5,2,5,2,5,2,5,2,5,2,14,15,12,13,18,17, +17,32,33,33,33,48,5,2,49,33,33,48,5,2,49,33,33,33,34,17, +17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, +17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,71,72,71,72,0,0,71,72,71,72,0,0,71,72,71,72,0,0, +0,0,67,68,69,70,0,0,67,68,69,70,0,0,67,68,69,70,0,0, +0,0,71,72,71,72,0,0,71,72,71,72,0,0,71,72,71,72,0,0, +0,0,67,68,69,70,0,0,67,68,69,70,0,0,67,68,69,70,0,0, +0,0,71,72,71,72,0,0,71,72,71,72,0,0,0,0,0,0,0,0, +0,0,67,68,69,70,0,0,67,68,69,70,0,0,0,0,0,0,0,0, +0,0,71,72,71,72,0,0,71,72,71,72,0,0,0,0,0,0,0,0, +0,0,67,68,69,70,0,0,67,68,69,70,0,0,0,0,0,0,0,0, +0,0,71,72,71,72,0,0,71,72,71,72,0,0,0,0,0,0,0,0, +0,0,67,68,69,70,0,0,67,68,69,70,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,71,72,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,83,84,69,70,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/data/mapa.lua b/data/mapa.lua index 1082106..6908bc1 100644 --- a/data/mapa.lua +++ b/data/mapa.lua @@ -23,6 +23,8 @@ mapa={ 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 @@ -33,6 +35,21 @@ mapa={ x=x+1 end end + + if num_layers==2 then + mapa.front_layer=newsurf(mapa.w,mapa.h) + setmap(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 + mset(x,y,m) + x=x+1 + end + end + end + setmap(mapa.surface) io.close(file) end end, @@ -44,12 +61,23 @@ mapa={ 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 + setmap(mapa.surface) for y=0,mapa.h-1 do for x=0,mapa.w-1 do io.write(mget(x,y)..",") end io.write("\n") end + if mapa.front_layer then + setmap(mapa.front_layer) + for y=0,mapa.h-1 do + for x=0,mapa.w-1 do + io.write(mget(x,y)..",") + end + io.write("\n") + end + end io.close(file) end end, diff --git a/data/test.map b/data/test.map index 10d4995..84678a3 100644 --- a/data/test.map +++ b/data/test.map @@ -1,5 +1,6 @@ 128 128 +1 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, diff --git a/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