From bbbf9d0c50a69753b1586705a2cb3c1304137631 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 19 Jun 2025 22:11:05 +0200 Subject: [PATCH] =?UTF-8?q?-=20[CHG]=20M=C3=B2dul=20"level"=20renomenat=20?= =?UTF-8?q?a=20"rooms"=20-=20[NEW]=20M=C3=B2dul=20"menu"=20-=20[NEW]=20M?= =?UTF-8?q?=C3=B2dul=20"popup"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/level.lua | 94 -------------------------------------- data/main.lua | 19 +++++--- data/menu.lua | 46 +++++++++++++++++++ data/popup.lua | 39 ++++++++++++++++ data/rooms.lua | 94 ++++++++++++++++++++++++++++++++++++++ data/rooms_background.bin | Bin 0 -> 227 bytes data/rooms_foreground.bin | Bin 0 -> 229 bytes data/rooms_items.bin | Bin 0 -> 227 bytes 8 files changed, 191 insertions(+), 101 deletions(-) delete mode 100644 data/level.lua create mode 100644 data/menu.lua create mode 100644 data/popup.lua create mode 100644 data/rooms.lua create mode 100644 data/rooms_background.bin create mode 100644 data/rooms_foreground.bin create mode 100644 data/rooms_items.bin diff --git a/data/level.lua b/data/level.lua deleted file mode 100644 index 6c960da..0000000 --- a/data/level.lua +++ /dev/null @@ -1,94 +0,0 @@ -level = { - surf_background = nil, - surf_foreground = nil, - surf_items = nil, - surf_original_items = nil, - - pos = {x=0, y=0}, - - init = function() - level.pos.x, level.pos.y = 0,0 - if level.surf_background ~= nil then surf.free(level.surf_background) end - --level.surf_background = surf.load("rooms_background.bin") - level.surf_background = surf.new(20*8,12*8) - - if level.surf_foreground ~= nil then surf.free(level.surf_foreground) end - --level.surf_foreground = surf.load("rooms_foreground.bin") - level.surf_foreground = surf.new(20*8,12*8) - - if level.surf_items ~= nil then surf.free(level.surf_items) end - --level.surf_items = surf.load("rooms_items.bin") - level.surf_items = surf.new(20*8,12*8) - - level.surf_original_items = surf.new(20*8,12*8) - surf.source(level.surf_items) - surf.target(level.surf_original_items) - draw.surf(0,0,160,96,0,0) - - map.surf(level.surf_background) - for y=0,12*8 do - for x=0,20*8 do - map.tile(x,y,1) - end - end - map.surf(level.surf_foreground) - map.tile(10,10,16) - - surf.save(level.surf_background, "data/rooms_background.bin") - surf.save(level.surf_foreground, "data/rooms_foreground.bin") - surf.save(level.surf_items, "data/rooms_items.bin") - - shader.init("lynx.glsl") - shader.enable(); - end, - - - draw = function() - -- Retallem la pantalla a la zona de joc - view.clip(0,8,160,96) - - -- Movem la càmara a l'habitació on estem - view.origin(level.pos.x*8,level.pos.y*8+8) - - -- Pintem el background - surf.source(tiles) - map.surf(level.surf_background) - map.draw() - - -- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground - view.origin(level.pos.x*8+4,level.pos.y*8+12) - - -- Pintem el foreground de negre - map.surf(level.surf_foreground) - pal.subpal(0,32,1) - map.draw() - - -- Pintem els sprites de negre - -- [TODO] - surf.source(sprites) - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) - - -- Movem la càmara al lloc que toca de nou, i tornem la paleta normal - view.origin(level.pos.x*8,level.pos.y*8+8) - pal.subpal() - - -- Pintem el foreground - surf.source(tiles) - map.surf(level.surf_foreground) - map.draw() - - -- Pintem els sprites - -- [TODO] - surf.source(sprites) - draw.surf(0, 0, 16, 17, 10, 10, 16, 17) - - -- Pintem la rejilla - --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end - --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end - end, - - peiv = function() - pal.color(1, 1, 1, 1) - return "HOLA OTHER UNIT" - end -} diff --git a/data/main.lua b/data/main.lua index 85acb00..6353769 100644 --- a/data/main.lua +++ b/data/main.lua @@ -1,5 +1,5 @@ -require "level" - +require "rooms" +require "menu" x=0 function mini.init() @@ -8,7 +8,8 @@ function mini.init() surf.source(tiles) pal.set(pal.load("tiles.gif")) pal.trans(0) - level.init() + rooms.init() + menu.show() end function mini.update() @@ -16,19 +17,23 @@ function mini.update() surf.cls(1) surf.target(0) + menu.draw() + -- Pintar el marcador -- [TODO] -- Pintar el mapa i sprites - level.draw() + rooms.draw() view.origin(0,0) local mx, my = mouse.pos() mx, my = math.floor(mx/8)*8, math.floor(my/8)*8 - draw.rect(mx-1, my-1, 10, 10, 28) - draw.rect(mx, my, 8, 8, 1) - if (key.down(key.ESCAPE)) then + if my>=8 then + draw.rect(mx-1, my-1, 10, 10, 28) + draw.rect(mx, my, 8, 8, 1) + end + if key.press(key.ESCAPE) then sys.quit() end end diff --git a/data/menu.lua b/data/menu.lua new file mode 100644 index 0000000..0fa86c7 --- /dev/null +++ b/data/menu.lua @@ -0,0 +1,46 @@ +require "popup" + +menu = { + visible = false, + current_x = 0, + + init = function() + end, + + show = function() + menu.visible = true + end, + + hide = function() + menu.visible = false + end, + + draw = function() + view.origin(0,0) + view.clip() + draw.rectf(0,0,160,7,23) + draw.hline(0,7,160,16) + menu.current_x = 1 + menu.option("FILE") + popup.create("FILE", 1, 8) + popup.addOption("FILE", "New", function() sys.quit() end) + popup.addOption("FILE", "Load", function() sys.quit() end) + popup.addOption("FILE", "Save", function() sys.quit() end) + popup.addOption("FILE", "Save As...", function() sys.quit() end) + menu.option("EDIT") + menu.option("TOOLS") + end, + + option = function(label) + local next_x = menu.current_x + (#label + 2)*4 + local mx, my = mouse.pos() + if my < 8 and mx >= menu.current_x and mx < next_x then + draw.rectf(menu.current_x, 0, next_x-menu.current_x, 8, 21) + if mouse.down(mouse.LEFT) then + popup.show(label) + end + end + draw.text(label,menu.current_x+4,1,28) + menu.current_x = next_x + end +} \ No newline at end of file diff --git a/data/popup.lua b/data/popup.lua new file mode 100644 index 0000000..d1d0a14 --- /dev/null +++ b/data/popup.lua @@ -0,0 +1,39 @@ +popup={ + list = {}, + old_update = nil, + current = nil, + + create = function(label,x,y) + popup.list[label] = {x=x, y=y, width=0, options={}} + end, + + addOption = function(parent, label, action) + popup.list[parent].options[#popup.list[parent].options+1] = { label=label, action=action } + local option_width = #label*4+4 + if option_width > popup.list[parent].width then + popup.list[parent].width = option_width + end + end, + + show = function(label) + popup.old_update = mini.update + popup.current = label + mini.update = popup.update + end, + + update = function() + local p = popup.list[popup.current] + draw.rectf(p.x, p.y, p.width, #p.options*7+2, 23) + draw.rect(p.x, p.y, p.width, #p.options*7+2, 16) + local y = p.y+2 + for k,v in ipairs(p.options) do + draw.text(v.label, p.x+2, y, 28) + y = y + 7 + end + + if key.press(key.ESCAPE) then + mini.update = popup.old_update + end + end + +} \ No newline at end of file diff --git a/data/rooms.lua b/data/rooms.lua new file mode 100644 index 0000000..beb0d24 --- /dev/null +++ b/data/rooms.lua @@ -0,0 +1,94 @@ +rooms = { + surf_background = nil, + surf_foreground = nil, + surf_items = nil, + surf_original_items = nil, + + pos = {x=10*8, y=0}, + + init = function() + rooms.pos.x, rooms.pos.y = 0,0 + if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end + rooms.surf_background = surf.load("rooms_background.bin") + --rooms.surf_background = surf.new(20*8,12*8) + + if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end + rooms.surf_foreground = surf.load("rooms_foreground.bin") + --rooms.surf_foreground = surf.new(20*8,12*8) + + if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end + rooms.surf_items = surf.load("rooms_items.bin") + --rooms.surf_items = surf.new(20*8,12*8) + + rooms.surf_original_items = surf.new(20*8,12*8) + surf.source(rooms.surf_items) + surf.target(rooms.surf_original_items) + draw.surf(0,0,160,96,0,0) + + --map.surf(rooms.surf_background) + --for y=0,12*8 do + -- for x=0,20*8 do + -- map.tile(x,y,1) + -- end + --end + --map.surf(rooms.surf_foreground) + --map.tile(10,10,16) + + --surf.save(rooms.surf_background, "data/rooms_background.bin") + --surf.save(rooms.surf_foreground, "data/rooms_foreground.bin") + --surf.save(rooms.surf_items, "data/rooms_items.bin") + + --shader.init("lynx.glsl") + --shader.enable(); + end, + + + draw = function() + -- Retallem la pantalla a la zona de joc + view.clip(0,8,160,96) + + -- Movem la càmara a l'habitació on estem + view.origin(rooms.pos.x*8,rooms.pos.y*8+8) + + -- Pintem el background + surf.source(tiles) + map.surf(rooms.surf_background) + map.draw() + + -- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground + view.origin(rooms.pos.x*8+4,rooms.pos.y*8+12) + + -- Pintem el foreground de negre + map.surf(rooms.surf_foreground) + pal.subpal(0,32,1) + map.draw() + + -- Pintem els sprites de negre + -- [TODO] + surf.source(sprites) + draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + + -- Movem la càmara al lloc que toca de nou, i tornem la paleta normal + view.origin(rooms.pos.x*8,rooms.pos.y*8+8) + pal.subpal() + + -- Pintem el foreground + surf.source(tiles) + map.surf(rooms.surf_foreground) + map.draw() + + -- Pintem els sprites + -- [TODO] + surf.source(sprites) + draw.surf(0, 0, 16, 17, 10, 10, 16, 17) + + -- Pintem la rejilla + --for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end + --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end + end, + + peiv = function() + pal.color(1, 1, 1, 1) + return "HOLA OTHER UNIT" + end +} diff --git a/data/rooms_background.bin b/data/rooms_background.bin new file mode 100644 index 0000000000000000000000000000000000000000..86d92717f120fe361e18ba088524c9521b9fda5b GIT binary patch literal 227 zcmV<90382ENk%w1VW0qD0C4{REC2ui0H6S1000Qc00RgdNU)&6g9sBUT*$DY!-o(f zN}NcsqQ#3CGiuz(v7^V2AVZ2ANwTELlPFWFT*%##706RYqb$kE- literal 0 HcmV?d00001 diff --git a/data/rooms_foreground.bin b/data/rooms_foreground.bin new file mode 100644 index 0000000000000000000000000000000000000000..d0ac5388e4c4146ec7d5192926407ca9f99f6e28 GIT binary patch literal 229 zcmVCNk%w1VW0qD0C4{REC2ui0H6S1000Qe009UbNU)&6g9sBUT*$DY!-o(f zN}NcsqQ#3CGiuz(v7^V2AVZ2ANwTELlPFWFT*({XL1_S^*o*Q;6 literal 0 HcmV?d00001 diff --git a/data/rooms_items.bin b/data/rooms_items.bin new file mode 100644 index 0000000000000000000000000000000000000000..ff7db0799fc8b918ca2adbd20c98bdc1bcaad2f4 GIT binary patch literal 227 zcmV<90382ENk%w1VW0qD0C4{REC2ui0H6S1000Qc009UbNU)&6g9sBUT*$DY!-o(f zN}NcsqQ#3CGiuz(v7^V2AVZ2ANwTELlPFWFT*%##706RT>b$S2* literal 0 HcmV?d00001