From 6c5d7a305a9ad60a6f9c07e665208257bee6ed80 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Thu, 12 Mar 2026 17:30:56 +0100 Subject: [PATCH] =?UTF-8?q?-=20Primera=20pasada=20de=20reorganitzaci=C3=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/animations.lua | 15 + data/app.lua | 21 +- data/console.lua | 545 +++++++++++++-------------- data/{ => gfx}/blava.gif | Bin data/{ => gfx}/groga.gif | Bin data/{ => gfx}/misc.gif | Bin data/{ => gfx}/morcus.gif | Bin data/{ => gfx}/mummy.gif | Bin data/{ => gfx}/roja.gif | Bin data/{ => gfx}/sprites.gif | Bin 3013 -> 3016 bytes data/gfx/sucubo.gif | Bin 0 -> 397 bytes data/{ => gfx}/tiles.gif | Bin data/{ => gfx}/torxa.gif | Bin data/{ => gfx}/verda.gif | Bin data/items.lua | 69 +--- data/main.lua | 6 +- data/{ => maps}/rooms_background.gif | Bin data/{ => maps}/rooms_foreground.gif | Bin data/{ => maps}/rooms_items.gif | Bin 1055 -> 1057 bytes data/menu.lua | 200 ++++------ data/msgbox.lua | 123 +++--- data/palfade.lua | 120 +++--- data/popup.lua | 52 --- data/rooms.lua | 211 +++++------ data/score.lua | 37 +- data/sprites.lua | 40 +- data/templates.lua | 265 +++++++------ data/tweening.lua | 222 +++++------ data/ui.lua | 91 ++--- data/util.lua | 44 ++- 30 files changed, 965 insertions(+), 1096 deletions(-) rename data/{ => gfx}/blava.gif (100%) rename data/{ => gfx}/groga.gif (100%) rename data/{ => gfx}/misc.gif (100%) rename data/{ => gfx}/morcus.gif (100%) rename data/{ => gfx}/mummy.gif (100%) rename data/{ => gfx}/roja.gif (100%) rename data/{ => gfx}/sprites.gif (81%) create mode 100644 data/gfx/sucubo.gif rename data/{ => gfx}/tiles.gif (100%) rename data/{ => gfx}/torxa.gif (100%) rename data/{ => gfx}/verda.gif (100%) rename data/{ => maps}/rooms_background.gif (100%) rename data/{ => maps}/rooms_foreground.gif (100%) rename data/{ => maps}/rooms_items.gif (88%) delete mode 100644 data/popup.lua diff --git a/data/animations.lua b/data/animations.lua index a3aa65a..0d73d28 100644 --- a/data/animations.lua +++ b/data/animations.lua @@ -165,4 +165,19 @@ animations = { { frame={x=16,y=15,w=8,h=1}, wait=1 }, } }, + ["sucubo_stand"] = { + cycle = {1}, + loop = false, + frames = { + { frame={x=0,y=0,w=16,h=16}, wait=100 }, + } + }, + ["sucubo_fire"] = { + cycle = {1,2}, + loop = false, + frames = { + { frame={x=16,y=0,w=22,h=16}, offset={normal={x=-6,y=0}}, wait=2 }, + { frame={x=38,y=0,w=15,h=16}, offset={normal={x=5,y=0}}, wait=4 }, + } + }, } \ No newline at end of file diff --git a/data/app.lua b/data/app.lua index 6058056..f3de876 100644 --- a/data/app.lua +++ b/data/app.lua @@ -1,16 +1,15 @@ app = { - update = nil, stack = {}, +} - push = function(func) - table.insert(app.stack, app.update) - app.update = func - end, +function app.push(func) + table.insert(app.stack, app.update) + app.update = func +end - pop = function() - if #app.stack > 0 then - app.update = table.remove(app.stack) - end - end, -} \ No newline at end of file +function app.pop() + if #app.stack > 0 then + app.update = table.remove(app.stack) + end +end diff --git a/data/console.lua b/data/console.lua index 7f7e73f..6a242fd 100644 --- a/data/console.lua +++ b/data/console.lua @@ -73,291 +73,290 @@ console = { autocomplete_list = {}, autocomplete_prefix = "", autocomplete_index = 1, +} local me = console - enable = function() - app.push(console.update) - console.command = "" - end, +function me.enable() + app.push(me.update) + me.command = "" +end - update = function() - surf.target(0) - draw.rrectf(0, 92, 160, 108, 4, 1) - draw.rrect(0, 92, 160, 108, 4, 13) - draw.text(">", 2, 96, 13) - draw.text(console.command, 6, 96, 13) +function me.update() + surf.target(0) + draw.rrectf(0, 92, 160, 108, 4, 1) + draw.rrect(0, 92, 160, 108, 4, 13) + draw.text(">", 2, 96, 13) + draw.text(me.command, 6, 96, 13) - if console.autocomplete_list and #console.autocomplete_list>0 then - --local num = math.min(5, #console.autocomplete_list) - --local base_y = 92-num*7 - --draw.rectf(3+#console.command*4, base_y, 80, num*7, 1) - --draw.rect(3+#console.command*4, base_y, 80, num*7, 13) - --for i=1,num do - -- draw.text(console.autocomplete_list[i], 6+#console.command*4, base_y+i*7, 13) - --end + if me.autocomplete_list and #me.autocomplete_list>0 then + --local num = math.min(5, #me.autocomplete_list) + --local base_y = 92-num*7 + --draw.rectf(3+#me.command*4, base_y, 80, num*7, 1) + --draw.rect(3+#me.command*4, base_y, 80, num*7, 13) + --for i=1,num do + -- draw.text(me.autocomplete_list[i], 6+#me.command*4, base_y+i*7, 13) + --end - local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) - draw.text(sufix, 6+#console.command*4, 96, 6) - end + local sufix = me.autocomplete_list[me.autocomplete_index]:sub(#me.autocomplete_prefix+1) + draw.text(sufix, 6+#me.command*4, 96, 6) + end - if console.cursor > 24 then - draw.text("_", 6+#console.command*4, 96, 13) - end - console.cursor = console.cursor - 1 - if console.cursor == 0 then console.cursor = 50 end + if me.cursor > 24 then + draw.text("_", 6+#me.command*4, 96, 13) + end + me.cursor = me.cursor - 1 + if me.cursor == 0 then me.cursor = 50 end - if key.press(key.ESCAPE) then - app.pop() - return - end + if key.press(key.ESCAPE) then + app.pop() + return + end - local should_update = false + local should_update = false - if #console.history>0 then - if key.press(key.UP) and console.history_pos > 1 then - console.history_pos = console.history_pos - 1 - console.command = console.history[console.history_pos] - should_update = true - elseif key.press(key.DOWN) and console.history_pos < #console.history then - console.history_pos = console.history_pos + 1 - console.command = console.history[console.history_pos] - should_update = true - end - end - - local k = key.press() - if k ~= key.UNKNOWN then + if #me.history>0 then + if key.press(key.UP) and me.history_pos > 1 then + me.history_pos = me.history_pos - 1 + me.command = me.history[me.history_pos] + should_update = true + elseif key.press(key.DOWN) and me.history_pos < #me.history then + me.history_pos = me.history_pos + 1 + me.command = me.history[me.history_pos] should_update = true - if k >= key.A and k <= key.Z then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. string.char(k+61) - else - console.command = console.command .. string.char(k+93) - end - elseif k == key.N0 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '=' - elseif key.down(key.RALT) then - console.command = console.command .. '}' - else - console.command = console.command .. '0' - end - elseif k == key.N1 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '!' - elseif key.down(key.RALT) then - console.command = console.command .. '|' - else - console.command = console.command .. '1' - end - elseif k == key.N2 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '"' - elseif key.down(key.RALT) then - console.command = console.command .. '@' - else - console.command = console.command .. '2' - end - elseif k == key.N3 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '·' - elseif key.down(key.RALT) then - console.command = console.command .. '#' - else - console.command = console.command .. '3' - end - elseif k == key.N4 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '$' - elseif key.down(key.RALT) then - console.command = console.command .. '~' - else - console.command = console.command .. '4' - end - elseif k == key.N5 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '%' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '5' - end - elseif k == key.N6 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '&' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '6' - end - elseif k == key.N7 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '/' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '7' - end - elseif k == key.N8 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '(' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '8' - end - elseif k == key.N9 then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. ')' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '9' - end - - elseif k == key.PERIOD then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. ':' - else - console.command = console.command .. '.' - end - - elseif k == key.COMMA then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. ';' - else - console.command = console.command .. ',' - end - - elseif k == key.GRAVE then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. ' ' - elseif key.down(key.RALT) then - console.command = console.command .. '\\' - else - console.command = console.command .. ' ' - end - - elseif k == key.EQUALS then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '¿' - else - console.command = console.command .. '¡' - end - - elseif k == key.SLASH then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '_' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '-' - end - - elseif k == key.APOSTROPHE then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '"' - elseif key.down(key.RALT) then - console.command = console.command .. '{' - else - console.command = console.command .. '\'' - end - - elseif k == key.SEMICOLON then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. 'Ñ' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. 'ñ' - end - - elseif k == key.BACKSLASH then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. 'Ç' - elseif key.down(key.RALT) then - console.command = console.command .. '}' - else - console.command = console.command .. 'ç' - end - - elseif k == key.RIGHTBRACKET then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '*' - elseif key.down(key.RALT) then - console.command = console.command .. ']' - else - console.command = console.command .. '+' - end - - elseif k == key.LEFTBRACKET then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '^' - elseif key.down(key.RALT) then - console.command = console.command .. '[' - else - console.command = console.command .. '`' - end - - elseif k == key.NONUSBACKSLASH then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '>' - elseif key.down(key.RALT) then - console.command = console.command .. ' ' - else - console.command = console.command .. '<' - end - - elseif k == key.MINUS then - if key.down(key.LSHIFT) or key.down(key.RSHIFT) then - console.command = console.command .. '?' - else - console.command = console.command .. '\'' - end - - elseif k == key.SPACE then - console.command = console.command .. ' ' - elseif k == key.BACKSPACE then - console.command = console.command:sub(1, #console.command - 1) - - elseif k == key.TAB then - local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) - console.command = console.command .. sufix - - elseif k == key.RETURN then - table.insert(console.history, console.command) - console.history_pos = #console.history+1 - local f,err = load(console.command) - if not f then - print("Error al compilar:", err) - else - print(f()) - app.pop() - end - end - end + end - if should_update then - local a, b = split_by_last_separator(console.command) - if b ~= "" then - local ba, bb = split_by_last_dot(b) - console.autocomplete_prefix = bb - if ba ~= "" then - console.autocomplete_list = entries_starting_with(bb, get_by_path(ba)) - --print(bb..":"..ba) - --print(#console.autocomplete_list) - else - console.autocomplete_list = entries_starting_with(bb, _G) - --print(bb..":".."golbal") - --print(#console.autocomplete_list) - end + local k = key.press() + if k ~= key.UNKNOWN then + should_update = true + if k >= key.A and k <= key.Z then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. string.char(k+61) else - console.autocomplete_prefix = "" - console.autocomplete_list = entries_starting_with("", _G) - --print(""..":".."golbal") - --print(#console.autocomplete_list) + me.command = me.command .. string.char(k+93) + end + elseif k == key.N0 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '=' + elseif key.down(key.RALT) then + me.command = me.command .. '}' + else + me.command = me.command .. '0' + end + elseif k == key.N1 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '!' + elseif key.down(key.RALT) then + me.command = me.command .. '|' + else + me.command = me.command .. '1' + end + elseif k == key.N2 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '"' + elseif key.down(key.RALT) then + me.command = me.command .. '@' + else + me.command = me.command .. '2' + end + elseif k == key.N3 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '·' + elseif key.down(key.RALT) then + me.command = me.command .. '#' + else + me.command = me.command .. '3' + end + elseif k == key.N4 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '$' + elseif key.down(key.RALT) then + me.command = me.command .. '~' + else + me.command = me.command .. '4' + end + elseif k == key.N5 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '%' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '5' + end + elseif k == key.N6 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '&' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '6' + end + elseif k == key.N7 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '/' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '7' + end + elseif k == key.N8 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '(' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '8' + end + elseif k == key.N9 then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. ')' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '9' + end + + elseif k == key.PERIOD then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. ':' + else + me.command = me.command .. '.' + end + + elseif k == key.COMMA then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. ';' + else + me.command = me.command .. ',' + end + + elseif k == key.GRAVE then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. ' ' + elseif key.down(key.RALT) then + me.command = me.command .. '\\' + else + me.command = me.command .. ' ' + end + + elseif k == key.EQUALS then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '¿' + else + me.command = me.command .. '¡' + end + + elseif k == key.SLASH then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '_' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '-' + end + + elseif k == key.APOSTROPHE then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '"' + elseif key.down(key.RALT) then + me.command = me.command .. '{' + else + me.command = me.command .. '\'' + end + + elseif k == key.SEMICOLON then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. 'Ñ' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. 'ñ' + end + + elseif k == key.BACKSLASH then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. 'Ç' + elseif key.down(key.RALT) then + me.command = me.command .. '}' + else + me.command = me.command .. 'ç' + end + + elseif k == key.RIGHTBRACKET then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '*' + elseif key.down(key.RALT) then + me.command = me.command .. ']' + else + me.command = me.command .. '+' + end + + elseif k == key.LEFTBRACKET then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '^' + elseif key.down(key.RALT) then + me.command = me.command .. '[' + else + me.command = me.command .. '`' + end + + elseif k == key.NONUSBACKSLASH then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '>' + elseif key.down(key.RALT) then + me.command = me.command .. ' ' + else + me.command = me.command .. '<' + end + + elseif k == key.MINUS then + if key.down(key.LSHIFT) or key.down(key.RSHIFT) then + me.command = me.command .. '?' + else + me.command = me.command .. '\'' + end + + elseif k == key.SPACE then + me.command = me.command .. ' ' + elseif k == key.BACKSPACE then + me.command = me.command:sub(1, #me.command - 1) + + elseif k == key.TAB then + local sufix = me.autocomplete_list[me.autocomplete_index]:sub(#me.autocomplete_prefix+1) + me.command = me.command .. sufix + + elseif k == key.RETURN then + table.insert(me.history, me.command) + me.history_pos = #me.history+1 + local f,err = load(me.command) + if not f then + print("Error al compilar:", err) + else + print(f()) + app.pop() end end - end, -} \ No newline at end of file + end + + if should_update then + local a, b = split_by_last_separator(me.command) + if b ~= "" then + local ba, bb = split_by_last_dot(b) + me.autocomplete_prefix = bb + if ba ~= "" then + me.autocomplete_list = entries_starting_with(bb, get_by_path(ba)) + --print(bb..":"..ba) + --print(#me.autocomplete_list) + else + me.autocomplete_list = entries_starting_with(bb, _G) + --print(bb..":".."golbal") + --print(#me.autocomplete_list) + end + else + me.autocomplete_prefix = "" + me.autocomplete_list = entries_starting_with("", _G) + --print(""..":".."golbal") + --print(#me.autocomplete_list) + end + end +end diff --git a/data/blava.gif b/data/gfx/blava.gif similarity index 100% rename from data/blava.gif rename to data/gfx/blava.gif diff --git a/data/groga.gif b/data/gfx/groga.gif similarity index 100% rename from data/groga.gif rename to data/gfx/groga.gif diff --git a/data/misc.gif b/data/gfx/misc.gif similarity index 100% rename from data/misc.gif rename to data/gfx/misc.gif diff --git a/data/morcus.gif b/data/gfx/morcus.gif similarity index 100% rename from data/morcus.gif rename to data/gfx/morcus.gif diff --git a/data/mummy.gif b/data/gfx/mummy.gif similarity index 100% rename from data/mummy.gif rename to data/gfx/mummy.gif diff --git a/data/roja.gif b/data/gfx/roja.gif similarity index 100% rename from data/roja.gif rename to data/gfx/roja.gif diff --git a/data/sprites.gif b/data/gfx/sprites.gif similarity index 81% rename from data/sprites.gif rename to data/gfx/sprites.gif index 8b478fe8038058e8aa3c54559f4b96e006c1c397..61de319a9a8c084ed08c8837eff7832d5622e9bb 100644 GIT binary patch delta 508 zcmV z6K5YZ`nmu3I+l=FACKFz!N&qWn}7b@6-|2=TmOY-f1ih6fOKwZhGlHFePt(Moo0Z$ z2Pi3X009SZyCDM)2z@{{ZeN50rI&wS^BlC1fiAFtwPb9Bhju;WRCICzOD2LggePG2 zV(Mi9IEaHO7<7N%W&k;;gSGU7765ielq1dORNo_mN>W)km{>#Da@>}Km864BIE6zf zb4PRn*N24uql9+BgoyQn6DM>{D27s)gHLDPPn1*bWVH-9oD9C|DsJKQQ7jOfIDsJbB@u!LQ2XGw+8gAHl ycsGE+2#f`2fYU)jsbY)uH+!9ej4`H+&iIVb7>&|6jnr6;)_9HBn2jkA0suQllk;i- delta 505 zcmV#2jUZ|Zb+`@AfJboBY zT|y-u$>S5f?-G53Fu4yuxol_V+Y3&MzMi^PkG+y@&jQE$zVA)uC$&c>}lID|5H zL??iKPW3U9=O;^uSU)&%LdS$*7=<}lbpn2dfb#r)zK?sUhsEG@xgc0b0@<&KQ9T#u|hbj%oisqMz>j!Wh2O4eIcz8E} vzUYeuXn@l}LP|)BF{XN^VvNU#jLg`K&iIVb7>&|6jnr6;)_9GQ5&{4_w;1J1 diff --git a/data/gfx/sucubo.gif b/data/gfx/sucubo.gif new file mode 100644 index 0000000000000000000000000000000000000000..43b3e15573325ece2bbb08171feba07e24ef0699 GIT binary patch literal 397 zcmZ?wbh9u|bYKu*IKlu036{eC+A3Pgp0ySZM#1sL$>IMQ7@DFDyHc$e)dn8SiLTz{ z_xr5W%(l`Q?d3-&hMb*O@M321hrQ*F4GT)v?%ub1)A0@Se&3&c?9k!=KcD>j57Z3> zia%L6xqxgP5FcbG1MB|;1*V3KSt+ZQJ>R+M?T>Ry1*W*Kdv4zQe%CxL2A*GGjJNp@ z=WwMTaTb0o^=#Rh=Z2Y+l2%5)^mGW@v?t>2HMbJB6|W*T#n@UeW#8I=`<#*ihm)F5 zYKnS8VTM3{X|}miaFR-Keq^)nB>f39rY5*g_L}Wypd=vCJw4CJAaC(}Qzbz`!+>S% ze47m2RChKn>t4Trk?+V+KFKQ8ZO4wBuyH=R?1bt;o&5rW#|6#@Ot^8Y_tZ^+6(>#R z<_B%NvsL2Nyjky-f4HhDk+aOFyK+9`&*g=GOc}%SImG!mEHfgux;s0yuI{jDi4f@I obnEz2kRh@1VvK$4n{!;Of(QFfbjDtFVqmZa0HtiDZ~y=R literal 0 HcmV?d00001 diff --git a/data/tiles.gif b/data/gfx/tiles.gif similarity index 100% rename from data/tiles.gif rename to data/gfx/tiles.gif diff --git a/data/torxa.gif b/data/gfx/torxa.gif similarity index 100% rename from data/torxa.gif rename to data/gfx/torxa.gif diff --git a/data/verda.gif b/data/gfx/verda.gif similarity index 100% rename from data/verda.gif rename to data/gfx/verda.gif diff --git a/data/items.lua b/data/items.lua index 929a959..3d8b553 100644 --- a/data/items.lua +++ b/data/items.lua @@ -1,57 +1,14 @@ items = { - [1] = { - name="mummy", - label="momia", - visual = {x=0,y=24,w=16,h=16} - }, - [2] = { - name="coin", - label="moneda", - visual = {x=0,y=40,w=8,h=8} - }, - [3] = { - name="torxa", - label="torxa", - visual = {x=0,y=48,w=8,h=16} - }, - [4] = { - name="clau verda", - label="clau", - visual = {x=16,y=48,w=16,h=8} - }, - [5] = { - name="clau groga", - label="clau", - visual = {x=16,y=56,w=16,h=8} - }, - [6] = { - name="clau roja", - label="clau", - visual = {x=32,y=48,w=16,h=8} - }, - [7] = { - name="clau blava", - label="clau", - visual = {x=32,y=56,w=16,h=8} - }, - [8] = { - name="porta verda", - label="porta", - visual = {x=48,y=48,w=8,h=16} - }, - [9] = { - name="porta groga", - label="porta", - visual = {x=56,y=48,w=8,h=16} - }, - [10] = { - name="porta roja", - label="porta", - visual = {x=64,y=48,w=8,h=16} - }, - [11] = { - name="porta blava", - label="porta", - visual = {x=72,y=48,w=8,h=16} - }, -} \ No newline at end of file + { name="mummy", label="momia", visual={x=0, y=24, w=16, h=16} }, + { name="coin", label="moneda", visual={x=0, y=40, w=8, h=8} }, + { name="torxa", label="torxa", visual={x=0, y=48, w=8, h=16} }, + { name="clau verda", label="clau", visual={x=16, y=48, w=16, h=8} }, + { name="clau groga", label="clau", visual={x=16, y=56, w=16, h=8} }, + { name="clau roja", label="clau", visual={x=32, y=48, w=16, h=8} }, + { name="clau blava", label="clau", visual={x=32, y=56, w=16, h=8} }, + { name="porta verda", label="porta", visual={x=48, y=48, w=8, h=16} }, + { name="porta groga", label="porta", visual={x=56, y=48, w=8, h=16} }, + { name="porta roja", label="porta", visual={x=64, y=48, w=8, h=16} }, + { name="porta blava", label="porta", visual={x=72, y=48, w=8, h=16} }, + { name="sucubo", label="sucubo", visual={x=0, y=64, w=16, h=16} }, +} diff --git a/data/main.lua b/data/main.lua index f27f516..41ef2eb 100644 --- a/data/main.lua +++ b/data/main.lua @@ -8,10 +8,10 @@ require "palfade" function reload_textures() if surf_sprites then surf.free(surf_sprites) end - surf_sprites = surf.load("sprites.gif") + surf_sprites = surf.load("gfx/sprites.gif") if surf_tiles then surf.free(surf_tiles) end - surf_tiles = surf.load("tiles.gif") - palfade.original = pal.load("tiles.gif") + surf_tiles = surf.load("gfx/tiles.gif") + palfade.original = pal.load("gfx/tiles.gif") pal.set(palfade.original) end diff --git a/data/rooms_background.gif b/data/maps/rooms_background.gif similarity index 100% rename from data/rooms_background.gif rename to data/maps/rooms_background.gif diff --git a/data/rooms_foreground.gif b/data/maps/rooms_foreground.gif similarity index 100% rename from data/rooms_foreground.gif rename to data/maps/rooms_foreground.gif diff --git a/data/rooms_items.gif b/data/maps/rooms_items.gif similarity index 88% rename from data/rooms_items.gif rename to data/maps/rooms_items.gif index 0dd3250eba733595189a30aabfd013af458cb7a8..7d9346cb9ee064d1b5ca05b9a870c3336816c41f 100644 GIT binary patch delta 106 zcmV-w0G0or2%!kDzXM_{kO4-+jwe&z%(=7YteQVl4DEO^!2=O7i(bvTwdH}6aN)?4E1w!DA@SwVqq{v0y?H|GoSzG%F1@?=@1hrg M1|Ltp{L+8`JJuvL;s5{u delta 104 zcmV-u0GI!v2%iYBzXM>r(XivmlrwAI%sDIO&J;g8UQF;nM9ZL4t6t4|Cu)JOTg#pe zAU5rWwr>v<9hkT7-xYJ?wCo$W@#Dy+21+PAx%204i#uPQkhS61>VDp K1RuXNAOJhgA2eP7 diff --git a/data/menu.lua b/data/menu.lua index d64971b..f27168e 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -1,144 +1,90 @@ -require "popup" require "ui" menu = { hidden = true, pos_y = 0, selected = 1, +} local me = menu - draw = function() - actions = { - function() editor.play() menu.close() end, - function() rooms.save() editor.modified=false menu.close() end, - function() editor.quit() menu.close() end, - function() editor.layer=LAYER_FOREGROUND menu.close() end, - function() editor.layer=LAYER_BACKGROUND menu.close() end, - function() editor.layer=LAYER_ITEMS menu.close() end, - function() rooms.toggle_visibility(LAYER_FOREGROUND) end, - function() rooms.toggle_visibility(LAYER_BACKGROUND) end, - function() rooms.toggle_visibility(LAYER_SHADOWS) end, - function() rooms.toggle_visibility(LAYER_ITEMS) end - } +function me.draw() + actions = { + function() editor.play() me.close() end, + function() rooms.save() editor.modified=false me.close() end, + function() editor.quit() me.close() end, + function() editor.layer=LAYER_FOREGROUND me.close() end, + function() editor.layer=LAYER_BACKGROUND me.close() end, + function() editor.layer=LAYER_ITEMS me.close() end, + function() rooms.toggle_visibility(LAYER_FOREGROUND) end, + function() rooms.toggle_visibility(LAYER_BACKGROUND) end, + function() rooms.toggle_visibility(LAYER_SHADOWS) end, + function() rooms.toggle_visibility(LAYER_ITEMS) end + } - local sel = menu.selected - view.origin(0,menu.pos_y) - view.clip() - local y = menu.pos_y - draw.rrectf(1,0,8,8,1,21) - draw.rrectf(1,-1,8,8,1,6) - draw.hline(3,1,6,21) - draw.hline(3,3,6,21) - draw.hline(3,5,6,21) - if editor.modified then draw.rectf(6,0,2,2,8) end + local sel = me.selected + view.origin(0,me.pos_y) + view.clip() + local y = me.pos_y + draw.rrectf(1,0,8,8,1,21) + draw.rrectf(1,-1,8,8,1,6) + draw.hline(3,1,6,21) + draw.hline(3,3,6,21) + draw.hline(3,5,6,21) + if editor.modified then draw.rectf(6,0,2,2,8) end - if y<=0 then return end + if y<=0 then return end - view.origin(0,menu.pos_y-24) - draw.rectf(0,0,160,24,6) + view.origin(0,me.pos_y-24) + draw.rectf(0,0,160,24,6) - ui.pushbutton("PLAY",1,3,16,13,10,actions[1], sel==1) - ui.pushbutton("SAVE",22,3,7,22,21,actions[2], sel==2) - if editor.modified then draw.rectf(37,4,2,2,8) end - ui.pushbutton("QUIT",22,12,7,12,5,actions[3], sel==3) + ui.pushbutton("PLAY",1,3,16,13,10,actions[1], sel==1) + ui.pushbutton("SAVE",22,3,7,22,21,actions[2], sel==2) + if editor.modified then draw.rectf(37,4,2,2,8) end + ui.pushbutton("QUIT",22,12,7,12,5,actions[3], sel==3) - draw.rrect(44,6,29,14,3,21) - draw.rectf(48,6,17,1,6) - draw.text("EDIT",49,3,21) - ui.togglebutton("F",44+3,6+3,7,14,9,15,7,editor.layer==LAYER_FOREGROUND,actions[4], sel==4) - ui.togglebutton("B",52+3,6+3,7,14,9,15,7,editor.layer==LAYER_BACKGROUND,actions[5], sel==5) - ui.togglebutton("I",60+3,6+3,7,14,9,15,7,editor.layer==LAYER_ITEMS,actions[6], sel==6) + draw.rrect(44,6,29,14,3,21) + draw.rectf(48,6,17,1,6) + draw.text("EDIT",49,3,21) + ui.togglebutton("F",44+3,6+3,7,14,9,15,7,editor.layer==LAYER_FOREGROUND,actions[4], sel==4) + ui.togglebutton("B",52+3,6+3,7,14,9,15,7,editor.layer==LAYER_BACKGROUND,actions[5], sel==5) + ui.togglebutton("I",60+3,6+3,7,14,9,15,7,editor.layer==LAYER_ITEMS,actions[6], sel==6) - draw.rrect(75,6,37,14,3,21) - draw.rectf(79,6,17,1,6) - draw.text("SHOW",80,3,21) + draw.rrect(75,6,37,14,3,21) + draw.rectf(79,6,17,1,6) + draw.text("SHOW",80,3,21) - ui.togglebutton("F",75+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_FOREGROUND),actions[7], sel==7) - ui.togglebutton("B",83+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_BACKGROUND),actions[8], sel==8) - ui.togglebutton("S",91+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_SHADOWS),actions[9], sel==9) - ui.togglebutton("I",99+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_ITEMS),actions[10], sel==10) + ui.togglebutton("F",75+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_FOREGROUND),actions[7], sel==7) + ui.togglebutton("B",83+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_BACKGROUND),actions[8], sel==8) + ui.togglebutton("S",91+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_SHADOWS),actions[9], sel==9) + ui.togglebutton("I",99+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_ITEMS),actions[10], sel==10) - local tab = key.press(key.TAB) - if key.press(key.ESCAPE) then - menu.toggle() - elseif key.press(key.LEFT) or (tab and key.down(key.LSHIFT)) then - menu.selected=menu.selected-1 - if menu.selected < 1 then menu.selected = 10 end - elseif key.press(key.RIGHT) or (tab and not key.down(key.LSHIFT)) then - menu.selected=menu.selected+1 - if menu.selected > 10 then menu.selected = 1 end - elseif key.press(key.RETURN) or key.press(key.SPACE) then - actions[menu.selected]() - end - end, + local tab = key.press(key.TAB) + if key.press(key.ESCAPE) then + me.toggle() + elseif key.press(key.LEFT) or (tab and key.down(key.LSHIFT)) then + me.selected=me.selected-1 + if me.selected < 1 then me.selected = 10 end + elseif key.press(key.RIGHT) or (tab and not key.down(key.LSHIFT)) then + me.selected=me.selected+1 + if me.selected > 10 then me.selected = 1 end + elseif key.press(key.RETURN) or key.press(key.SPACE) then + actions[me.selected]() + end +end - toggle = function() - if menu.hidden then - menu.hidden = false - menu.selected = 1 - tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) - else - menu.hidden = true - tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) - end - end, +function me.toggle() + if me.hidden then + me.hidden = false + me.selected = 1 + tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end) + else + me.hidden = true + tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end) + end +end - close = function() - if not menu.hidden then - menu.hidden = true - tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) - end - end, - --- current_x = 0, --- --- init = function() --- 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", "Play", editor.play) --- popup.addOption("FILE", "Save", function() rooms.save() editor.modified=false end) --- popup.addOption("FILE", "Quit", editor.quit) --- --- menu.option("VIEW") --- popup.create("VIEW", 1, 8) --- popup.addOption("VIEW", "Background", function() rooms.toggle_visibility(LAYER_BACKGROUND) end) --- popup.addOption("VIEW", "Shadows", function() rooms.toggle_visibility(LAYER_SHADOWS) end) --- popup.addOption("VIEW", "Foreground", function() rooms.toggle_visibility(LAYER_FOREGROUND) end) --- popup.addOption("VIEW", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) --- --- menu.option("EDIT") --- popup.create("EDIT", 1, 8) --- popup.addOption("EDIT", "Background", function() editor.layer=LAYER_BACKGROUND end) --- popup.addOption("EDIT", "Foreground", function() editor.layer=LAYER_FOREGROUND end) --- popup.addOption("EDIT", "Items", function() editor.layer=LAYER_ITEMS end) --- --popup.addOption("EDIT", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end) --- --- menu.option("TOOLS") --- if editor.modified then --- draw.text("*",160-5,1,8) --- end --- --- 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, 7, 21) --- if mouse.down(mouse.LEFT) then --- mouse.discard() --- 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 +function me.close() + if not me.hidden then + me.hidden = true + tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end) + end +end diff --git a/data/msgbox.lua b/data/msgbox.lua index 6286511..06c6bb1 100644 --- a/data/msgbox.lua +++ b/data/msgbox.lua @@ -8,76 +8,59 @@ msgbox = { selected = 0, w = 100, h = 50, +} local me = msgbox - show = function(title, text, buttons, default) - msgbox.selected = default or 1 - msgbox.title = title - msgbox.text = text - msgbox.buttons = buttons +function me.show(title, text, buttons, default) + me.selected = default or 1 + me.title = title + me.text = text + me.buttons = buttons - msgbox.w = 0 - for i,v in ipairs(msgbox.text) do - local width = #v*4+8 - if width > msgbox.w then msgbox.w = width end - end - - msgbox.h = #msgbox.text*6+35 - - app.push(msgbox.update) - end, - - update = function() - local top = (160-msgbox.w)//2 - local left = (104-msgbox.h)//2 - view.clip(top, left, msgbox.w, msgbox.h) - view.origin(top, left) - --draw.outset(0, 0, msgbox.w, msgbox.h) - draw.rrectf(0,0,msgbox.w, msgbox.h,4,27) - - --draw.rectf(1,1,msgbox.w-2, 7, 21) - draw.text(msgbox.title, 5, 4, 4) - - local y = 14 - for i,v in ipairs(msgbox.text) do - draw.text(v, 5, y, 21) - y = y + 6 - end - - local mx, my = mouse.pos() - - local x = msgbox.w - 35 - y = msgbox.h - 12 - for i,v in ipairs(msgbox.buttons) do - ui.pushbutton(v[1],x,y,7,22,21,v[2],msgbox.selected==i) - --local inside = util.inside(mx, my, {x, y, 32, 9}) - --draw.outset(x, y, 32, 9) - --if inside then - -- draw.rectf(x+1,y+1,30,7,27) - -- if mouse.down(mouse.LEFT) then draw.inset(x, y, 32, 9) end - --end - --local offset = (32-#v[1]*4)//2 - --draw.text(v[1], x+1+offset, y+2, 1) - --if (i==msgbox.selected) then - -- draw.rrect(x-1, y-1, 29, 10, 3, 1) - --end - --if mouse.press(mouse.LEFT) then - -- if inside then - -- v[2]() - -- end - --end - x = x - 34 - end - - if key.press(key.ESCAPE) then - app.pop() - elseif key.press(key.RIGHT) then - msgbox.selected=msgbox.selected-1 - if msgbox.selected==0 then msgbox.selected = #msgbox.buttons end - elseif key.press(key.LEFT) then - msgbox.selected=msgbox.selected+1 - if msgbox.selected>#msgbox.buttons then msgbox.selected = 1 end - elseif key.press(key.RETURN) then - msgbox.buttons[msgbox.selected][2]() - end + me.w = 0 + for i,v in ipairs(me.text) do + local width = #v*4+8 + if width > me.w then me.w = width end end -} \ No newline at end of file + + me.h = #me.text*6+35 + + app.push(me.update) +end + +function me.update() + local top = (160-me.w)//2 + local left = (104-me.h)//2 + view.clip(top, left, me.w, me.h) + view.origin(top, left) + draw.rrectf(0,0,me.w, me.h,4,27) + + --draw.rectf(1,1,me.w-2, 7, 21) + draw.text(me.title, 5, 4, 4) + + local y = 14 + for i,v in ipairs(me.text) do + draw.text(v, 5, y, 21) + y = y + 6 + end + + local mx, my = mouse.pos() + + local x = me.w - 35 + y = me.h - 12 + for i,v in ipairs(me.buttons) do + ui.pushbutton(v[1],x,y,7,22,21,v[2],me.selected==i) + x = x - 34 + end + + if key.press(key.ESCAPE) then + app.pop() + elseif key.press(key.RIGHT) then + me.selected=me.selected-1 + if me.selected==0 then me.selected = #me.buttons end + elseif key.press(key.LEFT) then + me.selected=me.selected+1 + if me.selected>#me.buttons then me.selected = 1 end + elseif key.press(key.RETURN) then + me.buttons[me.selected][2]() + end +end diff --git a/data/palfade.lua b/data/palfade.lua index debb5c6..53eca06 100644 --- a/data/palfade.lua +++ b/data/palfade.lua @@ -1,69 +1,63 @@ palfade = { original = {}, reddish = {}, +} local me = palfade - init = function () - for i=1,32 do - palfade.reddish[i] = {r=palfade.original[i].r, g=palfade.original[i].g, b=palfade.original[i].b} - end - end, - - luminance = function(r, g, b) - return (0.2126*r + 0.7152*g + 0.0722*b)/255 - end, - - reddish_limit = function(r, g, b) - local t = palfade.luminance(r, g, b) / 255 - - local R = 255 * t - local G = g * (1 - t) - local B = b * (1 - t) - - return R, G, B - end, - - fade_reddish_color = function(r, g, b, f) - --local Rr, Gr, Br = palfade.reddish_limit(r, g, b) - local ff = math.min(1, f+palfade.luminance(r,g,b)) - local R = math.floor(r*ff)--math.floor(r + (Rr - r) * f) - local G = math.floor(g*f)--math.floor(g + (Gr - g) * f) - local B = math.floor(b*f)--math.floor(b + (Br - b) * f) --- local R = math.floor(r + (Rr - r) * f) --- local G = math.floor(g + (Gr - g) * f) --- local B = math.floor(b + (Br - b) * f) - - return R, G, B - end, - - fade_reddish = function(f) - for i=1,32 do - local r, g, b = palfade.fade_reddish_color(palfade.original[i].r, palfade.original[i].g, palfade.original[i].b, f) - palfade.reddish[i].r, palfade.reddish[i].g, palfade.reddish[i].b = r, g, b - pal.color(i-1,r,g,b) - end - end, - - fade_red = function(f) - for i=1,32 do - local r = math.floor(palfade.reddish[i].r + (255-palfade.reddish[i].r)*f) - local g = math.floor(palfade.reddish[i].g - (palfade.reddish[i].g)*f) - local b = math.floor(palfade.reddish[i].b - (palfade.reddish[i].b)*f) - pal.color(i-1,r,g,b) - end - - end, - - fade_white = function(f) - for i=1,32 do - local r = math.floor(palfade.reddish[i].r + (255-palfade.reddish[i].r)*f) - local g = math.floor(palfade.reddish[i].g + (255-palfade.reddish[i].g)*f) - local b = math.floor(palfade.reddish[i].b + (255-palfade.reddish[i].b)*f) - pal.color(i-1,r,g,b) - end - end, - - restore = function() - pal.set(palfade.original) +function me.init() + for i=1,32 do + me.reddish[i] = {r=me.original[i].r, g=me.original[i].g, b=me.original[i].b} end +end -} \ No newline at end of file +function luminance(r, g, b) + return (0.2126*r + 0.7152*g + 0.0722*b)/255 +end + +function me.reddish_limit(r, g, b) + local t = me.luminance(r, g, b) / 255 + + local R = 255 * t + local G = g * (1 - t) + local B = b * (1 - t) + + return R, G, B +end + +function me.fade_reddish_color(r, g, b, f) + local ff = math.min(1, f+me.luminance(r,g,b)) + local R = math.floor(r*ff) + local G = math.floor(g*f) + local B = math.floor(b*f) + + return R, G, B +end + +function me.fade_reddish(f) + for i=1,32 do + local r, g, b = me.fade_reddish_color(me.original[i].r, me.original[i].g, me.original[i].b, f) + me.reddish[i].r, me.reddish[i].g, me.reddish[i].b = r, g, b + pal.color(i-1,r,g,b) + end +end + +function me.fade_red(f) + for i=1,32 do + local r = math.floor(me.reddish[i].r + (255-me.reddish[i].r)*f) + local g = math.floor(me.reddish[i].g - (me.reddish[i].g)*f) + local b = math.floor(me.reddish[i].b - (me.reddish[i].b)*f) + pal.color(i-1,r,g,b) + end +end + +function me.fade_white(f) + for i=1,32 do + local r = math.floor(me.reddish[i].r + (255-me.reddish[i].r)*f) + local g = math.floor(me.reddish[i].g + (255-me.reddish[i].g)*f) + local b = math.floor(me.reddish[i].b + (255-me.reddish[i].b)*f) + pal.color(i-1,r,g,b) + end +end + +function me.restore() + pal.set(me.original) +end diff --git a/data/popup.lua b/data/popup.lua deleted file mode 100644 index d378c3a..0000000 --- a/data/popup.lua +++ /dev/null @@ -1,52 +0,0 @@ -popup={ - list = {}, - old_update = nil, - current = nil, - - create = function(label,x,y) - popup.list[label] = {x=x, y=y, width=50, 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.current = label - app.push(popup.update) - end, - - update = function() - view.origin(0,0) - local mx, my = mouse.pos() - local p = popup.list[popup.current] - draw.outset(p.x, p.y, p.width, #p.options*7+2) - local y = p.y+2 - for k,v in ipairs(p.options) do - local inside = util.inside(mx, my, {p.x, y-2, p.width, 7}) - if inside then - draw.rectf(p.x+1, y-1, p.width-2, 7, 21) - if mouse.press(mouse.LEFT) then - app.pop() - v.action() - end - end - draw.text(v.label, p.x+2, y, 28) - y = y + 7 - end - - local inside = util.inside(mx, my, {p.x, p.y, p.width, #p.options*7+2}) - if not inside and mouse.down(mouse.LEFT) then - mouse.discard() - app.pop() - end - if key.press(key.ESCAPE) then - app.pop() - end - end - -} \ No newline at end of file diff --git a/data/rooms.lua b/data/rooms.lua index b45b290..e5c7f51 100644 --- a/data/rooms.lua +++ b/data/rooms.lua @@ -15,136 +15,131 @@ rooms = { surf_original_items = nil, visibility = LAYER_ALL, pos = {x=0, y=4*13}, +} - current = function() - return (rooms.pos.x//20) + (rooms.pos.y//13) * 8 - end, +function rooms.current() + return (rooms.pos.x//20) + (rooms.pos.y//13) * 8 +end - convert = function(src) - local dst = surf.new(20*8,13*8) - surf.source(src) - surf.target(dst) +function rooms.convert(src) + local dst = surf.new(20*8,13*8) + surf.source(src) + surf.target(dst) - for ry=0,7 do - for rx=0,7 do - for ty=0,11 do - for tx=0,19 do - surf.pixel(rx*20+tx, ry*13+ty, surf.pixel(rx*20+tx, ry*12+ty)) - end + for ry=0,7 do + for rx=0,7 do + for ty=0,11 do + for tx=0,19 do + surf.pixel(rx*20+tx, ry*13+ty, surf.pixel(rx*20+tx, ry*12+ty)) end end end - return dst - end, + end + return dst +end - reload = function() - if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end - rooms.surf_background = surf.load("rooms_background"..ROOM_FILE_EXT) - --rooms.surf_background = surf.new(20*8,13*8) - --rooms.surf_background = rooms.convert(surf.load("rooms_background"..ROOM_FILE_EXT)) +function rooms.reload() + if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end + rooms.surf_background = surf.load("maps/rooms_background"..ROOM_FILE_EXT) + --rooms.surf_background = surf.new(20*8,13*8) + --rooms.surf_background = rooms.convert(surf.load("rooms_background"..ROOM_FILE_EXT)) - if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end - rooms.surf_foreground = surf.load("rooms_foreground"..ROOM_FILE_EXT) - --rooms.surf_foreground = surf.new(20*8,12*8) - --rooms.surf_foreground = rooms.convert(surf.load("rooms_foreground"..ROOM_FILE_EXT)) + if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end + rooms.surf_foreground = surf.load("maps/rooms_foreground"..ROOM_FILE_EXT) + --rooms.surf_foreground = surf.new(20*8,12*8) + --rooms.surf_foreground = rooms.convert(surf.load("rooms_foreground"..ROOM_FILE_EXT)) - if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end - rooms.surf_items = surf.load("rooms_items"..ROOM_FILE_EXT) - --rooms.surf_items = surf.new(20*8,12*8) - --rooms.surf_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT)) - end, + if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end + rooms.surf_items = surf.load("maps/rooms_items"..ROOM_FILE_EXT) + --rooms.surf_items = surf.new(20*8,12*8) + --rooms.surf_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT)) +end - init = function() - rooms.pos.x, rooms.pos.y = 0,4*13 - rooms.reload() - sprites.init() - end, +function rooms.init() + rooms.pos.x, rooms.pos.y = 0,4*13 + rooms.reload() + sprites.init() +end - save = function() - local p = {} - for i=0,255 do p[i] = {r=i,g=i,b=i} end - surf.save(rooms.surf_background, "data/rooms_background"..ROOM_FILE_EXT, p) - surf.save(rooms.surf_foreground, "data/rooms_foreground"..ROOM_FILE_EXT, p) - surf.save(rooms.surf_items, "data/rooms_items"..ROOM_FILE_EXT, p) - editor.modified = false - end, +function rooms.save() + local p = {} + for i=0,255 do p[i] = {r=i,g=i,b=i} end + surf.save(rooms.surf_background, "data/maps/rooms_background"..ROOM_FILE_EXT, p) + surf.save(rooms.surf_foreground, "data/maps/rooms_foreground"..ROOM_FILE_EXT, p) + surf.save(rooms.surf_items, "data/maps/rooms_items"..ROOM_FILE_EXT, p) + editor.modified = false +end - is_outside = function(x, y) - return x < rooms.pos.x or y < rooms.pos.y or x > rooms.pos.x + 20 or y > rooms.pos.y + 13 - end, +function rooms.is_outside(x, y) + return x < rooms.pos.x or y < rooms.pos.y or x > rooms.pos.x + 20 or y > rooms.pos.y + 13 +end - draw = function() - -- Retallem la pantalla a la zona de joc - --view.clip(0,8,160,96) +function rooms.draw() + -- 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) + -- Movem la càmara a l'habitació on estem + view.origin(-rooms.pos.x*8,-rooms.pos.y*8) - -- Pintem el background - surf.source(surf_tiles) - map.surf(rooms.surf_background) - if rooms.is_visible(LAYER_BACKGROUND) then - map.draw() - else - draw.rectf(0,0,160,96,1) - end + -- Pintem el background + surf.source(surf_tiles) + map.surf(rooms.surf_background) + if rooms.is_visible(LAYER_BACKGROUND) then + map.draw() + else + draw.rectf(0,0,160,96,1) + end - -- 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+4) + -- 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+4) - -- Pintem el foreground de negre - map.surf(rooms.surf_foreground) - pal.subpal(0,32,1) - if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end + -- Pintem el foreground de negre + map.surf(rooms.surf_foreground) + pal.subpal(0,32,1) + if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end - -- Pintem els sprites de negre - if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then - sprites.draw(true) - --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) - end + -- Pintem els sprites de negre + if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then + sprites.draw(true) + --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) + end - -- 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) - pal.subpal() + -- 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) + pal.subpal() - -- Pintem el foreground - surf.source(surf_tiles) - map.surf(rooms.surf_foreground) - if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end + -- Pintem el foreground + surf.source(surf_tiles) + map.surf(rooms.surf_foreground) + if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end - -- Pintem els sprites - if rooms.is_visible(LAYER_SPRITES) then - sprites.draw() - --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) - end + -- Pintem els sprites + if rooms.is_visible(LAYER_SPRITES) then + sprites.draw() + --draw.surf(0, 0, 16, 17, 20, 15, 16, 17) + end - -- 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, + -- 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 - is_visible = function(layer) - return (app.update==game.update) or (rooms.visibility & layer == layer) - end, +function rooms.is_visible(layer) + return (app.update==game.update) or (rooms.visibility & layer == layer) +end - set_visibility = function(layer, visibility) - if visibility then - rooms.visibility = rooms.visibility | layer - else - rooms.visibility = rooms.visibility & ~layer - end - end, +function rooms.set_visibility(layer, visibility) + if visibility then + rooms.visibility = rooms.visibility | layer + else + rooms.visibility = rooms.visibility & ~layer + end +end - toggle_visibility = function(layer) - if rooms.visibility & layer == layer then - rooms.visibility = rooms.visibility & ~layer - else - rooms.visibility = rooms.visibility | layer - end - end, - - peiv = function() - pal.color(1, 1, 1, 1) - return "HOLA OTHER UNIT" - end, -} +function rooms.toggle_visibility(layer) + if rooms.visibility & layer == layer then + rooms.visibility = rooms.visibility & ~layer + else + rooms.visibility = rooms.visibility | layer + end +end diff --git a/data/score.lua b/data/score.lua index bd0b03c..15861ae 100644 --- a/data/score.lua +++ b/data/score.lua @@ -3,25 +3,24 @@ score = { color = 28, zoom = 1, surf = nil, +} local me = score - init = function() - score.points = 0 - score.surf = surf.load("sprites.gif") - end, +function me.init() + me.points = 0 + me.surf = surf.load("gfx/sprites.gif") +end - draw = function() - draw.rectf(0,0,160,8,1) - draw.text(string.format("%03d", score.points),1,1,score.color) - surf.source(score.surf) - if sprites.hero.keys["verda"] then draw.surf(16,48,16,8, 32,-1) end - if sprites.hero.keys["groga"] then draw.surf(16,56,16,8, 32,-1) end - if sprites.hero.keys["roja"] then draw.surf(32,48,16,8, 32,-1) end - if sprites.hero.keys["blava"] then draw.surf(32,56,16,8, 32,-1) end - end, +function me.draw() + draw.rectf(0,0,160,8,1) + draw.text(string.format("%03d", me.points),1,1,me.color) + surf.source(me.surf) + if sprites.hero.keys["verda"] then draw.surf(16,48,16,8, 32,-1) end + if sprites.hero.keys["groga"] then draw.surf(16,56,16,8, 32,-1) end + if sprites.hero.keys["roja"] then draw.surf(32,48,16,8, 32,-1) end + if sprites.hero.keys["blava"] then draw.surf(32,56,16,8, 32,-1) end +end - inc = function(value) - --print("score.inc()") - score.points = score.points + value - tweening.add(8, 0, 0.5, easing.linear, function(val,progress,finished) score.color = (math.floor(val)&1) == 0 and 28 or 14 end) - end -} +function me.inc(value) + me.points = me.points + value + tweening.add(8, 0, 0.5, easing.linear, function(val,progress,finished) me.color = (math.floor(val)&1) == 0 and 28 or 14 end) +end diff --git a/data/sprites.lua b/data/sprites.lua index 4a32b62..5093bce 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -54,7 +54,7 @@ sprites = { current_frame = 1, current_wait = 1, flipped = false, - surf = surf.load("morcus.gif"), + surf = surf.load("gfx/morcus.gif"), animation = "hero_stand", ia = sprites.update_hero, state = templates.ALIVE, @@ -155,7 +155,7 @@ sprites = { if sprites.hero.lives == 0 then sprites.hero.state = templates.DEAD - sprites.hero.surf = surf.load("mummy.gif") + sprites.hero.surf = surf.load("gfx/mummy.gif") sprites.set_animation(sprites.hero, "mummy_dying") sprites.hero.jumping = 0 sprites.hero.cooldown = 120 @@ -370,6 +370,42 @@ sprites = { end end, + update_sucubo = function(spr) + map.surf(rooms.surf_foreground) + if spr.state == templates.ALIVE then + if sprites.hero.state == templates.ALIVE then + local x1,y1,w1,h1 = util.aabb(spr) -- El meu aabb + local x2,y2,w2,h2 = util.aabb(sprites.hero) -- el aabb del heroi + -- Si toca al heroi... + if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then + sprites.hero_hit() + end + end + + elseif spr.state == templates.DYING then + if spr.animation ~= "mummy_dying" then + sprites.set_animation(spr, "mummy_dying") + spr.surf = surf.load("gfx/mummy.gif") + else + if spr.current_frame == 8 then + sprites.set_animation(spr, "mummy_dead") + spr.state = templates.DEAD + end + end + elseif spr.state == templates.DEAD then + if spr.current_wait == 1 then + sprites.set_animation(spr, "mummy_undying") + spr.state = templates.RESURRECTING + end + elseif spr.state == templates.RESURRECTING then + if spr.current_frame == 13 then + sprites.set_animation(spr, "sucubo_stand") + spr.surf = surf.load("gfx/sucubo.gif") + spr.state = templates.ALIVE + end + end + end, + update_hero = function() if sprites.hero.state == templates.DEAD then diff --git a/data/templates.lua b/data/templates.lua index dc71213..e294de8 100644 --- a/data/templates.lua +++ b/data/templates.lua @@ -3,129 +3,146 @@ templates = { DYING = 1, DEAD = 2, RESURRECTING = 3, +} local me = templates - create = function(type, options) - local sprite - local key, value = type:match("^(%S+)%s*(.*)$") +function me.create(type, options) + local sprite + local key, value = type:match("^(%S+)%s*(.*)$") - if key == "mummy" then - sprite = { - type = key, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=16,h=16 }, - bbo = { left=3, top=2, right=3, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load("mummy.gif"), - animation = "mummy_walk", - state = templates.ALIVE, - enemy = true, - room = options.room, - ia = sprites.update_mummy - } - elseif key == "bullet" then - sprite = { - type = key, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=4,h=3 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load("morcus.gif"), - animation = "bullet", - ia = sprites.update_bullet - } - elseif key == "coin" then - sprite = { - type = key, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=8,h=8 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load("misc.gif"), - animation = "coin", - state = templates.ALIVE, - timer = 0, - light = 15, - light_ox = 4, - light_oy = 4, - ia = sprites.update_coin - } - elseif key == "brick" then - sprite = { - type = key, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=8,h=8 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load("misc.gif"), - animation = "brick", - state = templates.ALIVE, - timeout = 10, - ia = sprites.update_brick - } - elseif key == "torxa" then - sprite = { - type = key, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=8,h=16 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load("torxa.gif"), - animation = "torxa", - state = templates.ALIVE, - light = 30, - light_ox = 4, - light_oy = 4, - no_shadow = true, - ia = sprites.update_torxa - } - elseif key == "clau" then - sprite = { - type = key, - color = value, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=16,h=8 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load(value..".gif"), - animation = "clau", - state = templates.ALIVE, - light = 15, - light_ox = 7, - light_oy = 4, - ia = sprites.update_clau - } - elseif key == "porta" then - sprite = { - type = key, - color = value, - pos = options.pos,--{ x=100, y=4*12*8+71 }, - size = { w=8,h=16 }, - bbo = { left=0, top=0, right=0, bottom=0 }, - current_frame = 1, - current_wait = 1, - flipped = options.flipped, - surf = surf.load(value..".gif"), - animation = "porta", - state = templates.ALIVE, - ia = sprites.update_porta - } - else - error("Template not recognized") - end - --sprite.room = rooms.current() - print("creat sprite de tipus "..type) - return sprite - end, -} \ No newline at end of file + if key == "mummy" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=16,h=16 }, + bbo = { left=3, top=2, right=3, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/mummy.gif"), + animation = "mummy_walk", + state = me.ALIVE, + enemy = true, + room = options.room, + ia = sprites.update_mummy + } + elseif key == "bullet" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=4,h=3 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/morcus.gif"), + animation = "bullet", + ia = sprites.update_bullet + } + elseif key == "coin" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=8,h=8 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/misc.gif"), + animation = "coin", + state = me.ALIVE, + timer = 0, + light = 15, + light_ox = 4, + light_oy = 4, + ia = sprites.update_coin + } + elseif key == "brick" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=8,h=8 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/misc.gif"), + animation = "brick", + state = me.ALIVE, + timeout = 10, + ia = sprites.update_brick + } + elseif key == "torxa" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=8,h=16 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/torxa.gif"), + animation = "torxa", + state = me.ALIVE, + light = 30, + light_ox = 4, + light_oy = 4, + no_shadow = true, + ia = sprites.update_torxa + } + elseif key == "clau" then + sprite = { + type = key, + color = value, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=16,h=8 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/"..value..".gif"), + animation = "clau", + state = me.ALIVE, + light = 15, + light_ox = 7, + light_oy = 4, + ia = sprites.update_clau + } + elseif key == "porta" then + sprite = { + type = key, + color = value, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=8,h=16 }, + bbo = { left=0, top=0, right=0, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/"..value..".gif"), + animation = "porta", + state = me.ALIVE, + ia = sprites.update_porta + } + elseif key == "sucubo" then + sprite = { + type = key, + pos = options.pos,--{ x=100, y=4*12*8+71 }, + size = { w=16,h=16 }, + bbo = { left=3, top=2, right=3, bottom=0 }, + current_frame = 1, + current_wait = 1, + flipped = options.flipped, + surf = surf.load("gfx/sucubo.gif"), + animation = "sucubo_stand", + state = me.ALIVE, + timer = 0, + enemy = true, + room = options.room, + ia = sprites.update_sucubo + } + else + error("Template not recognized") + end + --sprite.room = rooms.current() + print("creat sprite de tipus "..type) + return sprite +end diff --git a/data/tweening.lua b/data/tweening.lua index 20558e0..b1e025b 100644 --- a/data/tweening.lua +++ b/data/tweening.lua @@ -34,131 +34,131 @@ local function bounceOut(t) end end -easing = { - linear = function(t) return t end, +easing = {} local me = easing - -- Sine - easeInSine = function(t) return 1 - cos((t * pi) / 2) end, - easeOutSine = function(t) return sin((t * pi) / 2) end, - easeInOutSine = function(t) return -(cos(pi * t) - 1) / 2 end, +function me.linear(t) return t end - -- Quad - easeInQuad = function(t) return t * t end, - easeOutQuad = function(t) return 1 - (1 - t) * (1 - t) end, - easeInOutQuad = function(t) - if t < 0.5 then return 2 * t * t end - return 1 - ((-2 * t + 2)^2) / 2 - end, +-- Sine +function me.easeInSine(t) return 1 - cos((t * pi) / 2) end +function me.easeOutSine(t) return sin((t * pi) / 2) end +function me.easeInOutSine(t) return -(cos(pi * t) - 1) / 2 end - -- Cubic - easeInCubic = function(t) return t * t * t end, - easeOutCubic = function(t) return 1 - ((1 - t)^3) end, - easeInOutCubic = function(t) - if t < 0.5 then return 4 * t * t * t end - return 1 - ((-2 * t + 2)^3) / 2 - end, +-- Quad +function me.easeInQuad(t) return t * t end +function me.easeOutQuad(t) return 1 - (1 - t) * (1 - t) end +function me.easeInOutQuad(t) + if t < 0.5 then return 2 * t * t end + return 1 - ((-2 * t + 2)^2) / 2 +end - -- Expo - easeInExpo = function(t) return (t == 0) and 0 or (2^(10 * t - 10)) end, - easeOutExpo = function(t) return (t == 1) and 1 or 1 - (2^(-10 * t)) end, - easeInOutExpo = function(t) - if t == 0 then return 0 end - if t == 1 then return 1 end - if t < 0.5 then return (2^(20 * t - 10)) / 2 end - return (2 - (2^(-20 * t + 10))) / 2 - end, +-- Cubic +function me.easeInCubic(t) return t * t * t end +function me.easeOutCubic(t) return 1 - ((1 - t)^3) end +function me.easeInOutCubic(t) + if t < 0.5 then return 4 * t * t * t end + return 1 - ((-2 * t + 2)^3) / 2 +end - -- Back (overshoot) - easeInBack = function(t) return backIn(t) end, - easeOutBack = function(t) return backOut(t) end, - easeInOutBack = function(t) return backInOut(t) end, +-- Expo +function me.easeInExpo(t) return (t == 0) and 0 or (2^(10 * t - 10)) end +function me.easeOutExpo(t) return (t == 1) and 1 or 1 - (2^(-10 * t)) end +function me.easeInOutExpo(t) + if t == 0 then return 0 end + if t == 1 then return 1 end + if t < 0.5 then return (2^(20 * t - 10)) / 2 end + return (2 - (2^(-20 * t + 10))) / 2 +end - -- Elastic - easeInElastic = function(t) - if t == 0 then return 0 end - if t == 1 then return 1 end - local c4 = (2 * pi) / 3 - return -(2^(10 * t - 10)) * sin((t * 10 - 10.75) * c4) - end, - easeOutElastic = function(t) - if t == 0 then return 0 end - if t == 1 then return 1 end - local c4 = (2 * pi) / 3 - return (2^(-10 * t)) * sin((t * 10 - 0.75) * c4) + 1 - end, - easeInOutElastic = function(t) - if t == 0 then return 0 end - if t == 1 then return 1 end - local c5 = (2 * pi) / 4.5 - if t < 0.5 then - return -((2^(20 * t - 10)) * sin((20 * t - 11.125) * c5)) / 2 - end - return ((2^(-20 * t + 10)) * sin((20 * t - 11.125) * c5)) / 2 + 1 - end, +-- Back (overshoot) +function me.easeInBack(t) return backIn(t) end +function me.easeOutBack(t) return backOut(t) end +function me.easeInOutBack(t) return backInOut(t) end - -- Bounce - easeInBounce = function(t) return 1 - bounceOut(1 - t) end, - easeOutBounce = function(t) return bounceOut(t) end, - easeInOutBounce = function(t) - if t < 0.5 then return (1 - bounceOut(1 - 2 * t)) / 2 end - return (1 + bounceOut(2 * t - 1)) / 2 - end, +-- Elastic +function me.easeInElastic(t) + if t == 0 then return 0 end + if t == 1 then return 1 end + local c4 = (2 * pi) / 3 + return -(2^(10 * t - 10)) * sin((t * 10 - 10.75) * c4) +end +function me.easeOutElastic(t) + if t == 0 then return 0 end + if t == 1 then return 1 end + local c4 = (2 * pi) / 3 + return (2^(-10 * t)) * sin((t * 10 - 0.75) * c4) + 1 +end +function me.easeInOutElastic(t) + if t == 0 then return 0 end + if t == 1 then return 1 end + local c5 = (2 * pi) / 4.5 + if t < 0.5 then + return -((2^(20 * t - 10)) * sin((20 * t - 11.125) * c5)) / 2 + end + return ((2^(-20 * t + 10)) * sin((20 * t - 11.125) * c5)) / 2 + 1 +end + +-- Bounce +function me.easeInBounce(t) return 1 - bounceOut(1 - t) end +function me.easeOutBounce(t) return bounceOut(t) end +function me.easeInOutBounce(t) + if t < 0.5 then return (1 - bounceOut(1 - 2 * t)) / 2 end + return (1 + bounceOut(2 * t - 1)) / 2 +end -} tweening = { list = {}, +} me = tweening - add = function(from, to, duration, easingFun, callback) - local tween = { - from = from, - to = to, - duration = math.max(0.000001, duration or 0.001), - easing = easingFun, - callback = callback, - t = 0, - } - tweening.list[#tweening.list + 1] = tween - return tween - end, +function me.add(from, to, duration, easingFun, callback) + local tween = { + from = from, + to = to, + duration = math.max(0.000001, duration or 0.001), + easing = easingFun, + callback = callback, + t = 0, + } + me.list[#me.list + 1] = tween + return tween +end - update = function(dt) - if #tweening.list==0 then return end +function me.update(dt) + if #me.list==0 then return end - -- iterate backwards so we can remove finished tweens safely - for i = #tweening.list, 1, -1 do - local tw = tweening.list[i] - tw.t = tw.t + (dt or 0) - local progress = tw.t / tw.duration - if progress >= 1 then - -- finished: ensure final value, call callback with finished=true, remove - local value = tw.to - if tw.callback then - -- callback(value, normalizedProgress, finished) - tw.callback(value, 1, true) - end - table.remove(tweening.list, i) - else - -- in progress - local alpha = tw.easing(progress) - local value = tw.from + (tw.to - tw.from) * alpha - if tw.callback then tw.callback(value, progress, false) end + -- iterate backwards so we can remove finished tweens safely + for i = #me.list, 1, -1 do + local tw = me.list[i] + tw.t = tw.t + (dt or 0) + local progress = tw.t / tw.duration + if progress >= 1 then + -- finished: ensure final value, call callback with finished=true, remove + local value = tw.to + if tw.callback then + -- callback(value, normalizedProgress, finished) + tw.callback(value, 1, true) end + table.remove(me.list, i) + else + -- in progress + local alpha = tw.easing(progress) + local value = tw.from + (tw.to - tw.from) * alpha + if tw.callback then tw.callback(value, progress, false) end end - end, - - clear = function() - for i = #tweening.list, 1, -1 do table.remove(tweening.list, i) end - end, - - -- Optional helper: cancel a specific tween (pass the tween returned by add) - cancel = function(tween) - for i = #tweening.list, 1, -1 do - if tweening.list[i] == tween then - table.remove(tweening.list, i) - return true - end - end - return false end -} \ No newline at end of file +end + +function me.clear() + for i = #me.list, 1, -1 do table.remove(me.list, i) end +end + +-- Optional helper: cancel a specific tween (pass the tween returned by add) +function me.cancel(tween) + for i = #me.list, 1, -1 do + if me.list[i] == tween then + table.remove(me.list, i) + return true + end + end + return false +end diff --git a/data/ui.lua b/data/ui.lua index 360b650..d7c1f00 100644 --- a/data/ui.lua +++ b/data/ui.lua @@ -1,57 +1,40 @@ -ui = { - pushbutton = function(label,x,y,h,col1,col2,callback,selected) - local size = (#label*4)-1+4 - local text_y = (h-5)//2 - local button_h=0 - local mx, my = mouse.pos() - if mx>=x and mx=y and my=x and mx=y and my-1 then bh=bh-1 end - end - draw.rrectf(x,y+1,size,h,1,col2) - draw.rrectf(x,y-bh,size,h,1,col1) - draw.text(label,x+2,y+text_y-bh,col2) - if selected then - draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1) - end - end, -} -function draw.outset(x, y, w, h) - draw.rectf(x, y, w, h, 23) - w,h = w+x,h+y - draw.hline(x, h-1, w-1,16) - draw.vline(w-1, y, h-1,16) - draw.hline(x, y, w-1,28) - draw.vline(x, y, h-1,28) +function ui.pushbutton(label,x,y,h,col1,col2,callback,selected) + local size = (#label*4)-1+4 + local text_y = (h-5)//2 + local button_h=0 + local mx, my = mouse.pos() + if mx>=x and mx=y and my=x and mx=y and my-1 then bh=bh-1 end + end + draw.rrectf(x,y+1,size,h,1,col2) + draw.rrectf(x,y-bh,size,h,1,col1) + draw.text(label,x+2,y+text_y-bh,col2) + if selected then + draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1) + end +end diff --git a/data/util.lua b/data/util.lua index 6cf9231..527c4fa 100644 --- a/data/util.lua +++ b/data/util.lua @@ -1,26 +1,24 @@ -util={ +util={} - inside = function(x, y, rectangle) - if x >= rectangle[1] and - y >= rectangle[2] and - x < rectangle[3]+rectangle[1] and - y < rectangle[4]+rectangle[2] then - return true - else - return false - end - end, - - aabb = function(sprite) - local x = sprite.pos.x + sprite.bbo.left - local y = sprite.pos.y + sprite.bbo.top - local w = sprite.size.w - sprite.bbo.right - sprite.bbo.left - local h = sprite.size.h - sprite.bbo.bottom - sprite.bbo.top - return x, y, w, h - end, - - check_aabb_collision = function(x1,y1,w1,h1, x2,y2,w2,h2) - return ( x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2 ) +function util.inside(x, y, rectangle) + if x >= rectangle[1] and + y >= rectangle[2] and + x < rectangle[3]+rectangle[1] and + y < rectangle[4]+rectangle[2] then + return true + else + return false end +end -} \ No newline at end of file +function util.aabb(sprite) + local x = sprite.pos.x + sprite.bbo.left + local y = sprite.pos.y + sprite.bbo.top + local w = sprite.size.w - sprite.bbo.right - sprite.bbo.left + local h = sprite.size.h - sprite.bbo.bottom - sprite.bbo.top + return x, y, w, h +end + +function util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) + return ( x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2 ) +end