- Primera pasada de reorganització

This commit is contained in:
JailDoctor committed 2026-03-12 17:30:56 +01:00
1 parent 8f185fa47c
commit 6c5d7a305a
30 files changed
+415 -546

No files matched your search

+15
View File
@@ -165,4 +165,19 @@ animations = {
{ frame={x=16,y=15,w=8,h=1}, wait=1 }, { 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 },
}
},
} }
+5 -6
View File
@@ -1,16 +1,15 @@
app = { app = {
update = nil, update = nil,
stack = {}, stack = {},
}
push = function(func) function app.push(func)
table.insert(app.stack, app.update) table.insert(app.stack, app.update)
app.update = func app.update = func
end, end
pop = function() function app.pop()
if #app.stack > 0 then if #app.stack > 0 then
app.update = table.remove(app.stack) app.update = table.remove(app.stack)
end end
end, end
}
+106 -107
View File
@@ -73,37 +73,38 @@ console = {
autocomplete_list = {}, autocomplete_list = {},
autocomplete_prefix = "", autocomplete_prefix = "",
autocomplete_index = 1, autocomplete_index = 1,
} local me = console
enable = function() function me.enable()
app.push(console.update) app.push(me.update)
console.command = "" me.command = ""
end, end
update = function() function me.update()
surf.target(0) surf.target(0)
draw.rrectf(0, 92, 160, 108, 4, 1) draw.rrectf(0, 92, 160, 108, 4, 1)
draw.rrect(0, 92, 160, 108, 4, 13) draw.rrect(0, 92, 160, 108, 4, 13)
draw.text(">", 2, 96, 13) draw.text(">", 2, 96, 13)
draw.text(console.command, 6, 96, 13) draw.text(me.command, 6, 96, 13)
if console.autocomplete_list and #console.autocomplete_list>0 then if me.autocomplete_list and #me.autocomplete_list>0 then
--local num = math.min(5, #console.autocomplete_list) --local num = math.min(5, #me.autocomplete_list)
--local base_y = 92-num*7 --local base_y = 92-num*7
--draw.rectf(3+#console.command*4, base_y, 80, num*7, 1) --draw.rectf(3+#me.command*4, base_y, 80, num*7, 1)
--draw.rect(3+#console.command*4, base_y, 80, num*7, 13) --draw.rect(3+#me.command*4, base_y, 80, num*7, 13)
--for i=1,num do --for i=1,num do
-- draw.text(console.autocomplete_list[i], 6+#console.command*4, base_y+i*7, 13) -- draw.text(me.autocomplete_list[i], 6+#me.command*4, base_y+i*7, 13)
--end --end
local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) local sufix = me.autocomplete_list[me.autocomplete_index]:sub(#me.autocomplete_prefix+1)
draw.text(sufix, 6+#console.command*4, 96, 6) draw.text(sufix, 6+#me.command*4, 96, 6)
end end
if console.cursor > 24 then if me.cursor > 24 then
draw.text("_", 6+#console.command*4, 96, 13) draw.text("_", 6+#me.command*4, 96, 13)
end end
console.cursor = console.cursor - 1 me.cursor = me.cursor - 1
if console.cursor == 0 then console.cursor = 50 end if me.cursor == 0 then me.cursor = 50 end
if key.press(key.ESCAPE) then if key.press(key.ESCAPE) then
app.pop() app.pop()
@@ -112,14 +113,14 @@ console = {
local should_update = false local should_update = false
if #console.history>0 then if #me.history>0 then
if key.press(key.UP) and console.history_pos > 1 then if key.press(key.UP) and me.history_pos > 1 then
console.history_pos = console.history_pos - 1 me.history_pos = me.history_pos - 1
console.command = console.history[console.history_pos] me.command = me.history[me.history_pos]
should_update = true should_update = true
elseif key.press(key.DOWN) and console.history_pos < #console.history then elseif key.press(key.DOWN) and me.history_pos < #me.history then
console.history_pos = console.history_pos + 1 me.history_pos = me.history_pos + 1
console.command = console.history[console.history_pos] me.command = me.history[me.history_pos]
should_update = true should_update = true
end end
end end
@@ -129,204 +130,204 @@ console = {
should_update = true should_update = true
if k >= key.A and k <= key.Z then if k >= key.A and k <= key.Z then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. string.char(k+61) me.command = me.command .. string.char(k+61)
else else
console.command = console.command .. string.char(k+93) me.command = me.command .. string.char(k+93)
end end
elseif k == key.N0 then elseif k == key.N0 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '=' me.command = me.command .. '='
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '}' me.command = me.command .. '}'
else else
console.command = console.command .. '0' me.command = me.command .. '0'
end end
elseif k == key.N1 then elseif k == key.N1 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '!' me.command = me.command .. '!'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '|' me.command = me.command .. '|'
else else
console.command = console.command .. '1' me.command = me.command .. '1'
end end
elseif k == key.N2 then elseif k == key.N2 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '"' me.command = me.command .. '"'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '@' me.command = me.command .. '@'
else else
console.command = console.command .. '2' me.command = me.command .. '2'
end end
elseif k == key.N3 then elseif k == key.N3 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '·' me.command = me.command .. '·'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '#' me.command = me.command .. '#'
else else
console.command = console.command .. '3' me.command = me.command .. '3'
end end
elseif k == key.N4 then elseif k == key.N4 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '$' me.command = me.command .. '$'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '~' me.command = me.command .. '~'
else else
console.command = console.command .. '4' me.command = me.command .. '4'
end end
elseif k == key.N5 then elseif k == key.N5 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '%' me.command = me.command .. '%'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '5' me.command = me.command .. '5'
end end
elseif k == key.N6 then elseif k == key.N6 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '&' me.command = me.command .. '&'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '6' me.command = me.command .. '6'
end end
elseif k == key.N7 then elseif k == key.N7 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '/' me.command = me.command .. '/'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '7' me.command = me.command .. '7'
end end
elseif k == key.N8 then elseif k == key.N8 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '(' me.command = me.command .. '('
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '8' me.command = me.command .. '8'
end end
elseif k == key.N9 then elseif k == key.N9 then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. ')' me.command = me.command .. ')'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '9' me.command = me.command .. '9'
end end
elseif k == key.PERIOD then elseif k == key.PERIOD then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. ':' me.command = me.command .. ':'
else else
console.command = console.command .. '.' me.command = me.command .. '.'
end end
elseif k == key.COMMA then elseif k == key.COMMA then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. ';' me.command = me.command .. ';'
else else
console.command = console.command .. ',' me.command = me.command .. ','
end end
elseif k == key.GRAVE then elseif k == key.GRAVE then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '\\' me.command = me.command .. '\\'
else else
console.command = console.command .. ' ' me.command = me.command .. ' '
end end
elseif k == key.EQUALS then elseif k == key.EQUALS then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '¿' me.command = me.command .. '¿'
else else
console.command = console.command .. '¡' me.command = me.command .. '¡'
end end
elseif k == key.SLASH then elseif k == key.SLASH then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '_' me.command = me.command .. '_'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '-' me.command = me.command .. '-'
end end
elseif k == key.APOSTROPHE then elseif k == key.APOSTROPHE then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '"' me.command = me.command .. '"'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '{' me.command = me.command .. '{'
else else
console.command = console.command .. '\'' me.command = me.command .. '\''
end end
elseif k == key.SEMICOLON then elseif k == key.SEMICOLON then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. 'Ñ' me.command = me.command .. 'Ñ'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. 'ñ' me.command = me.command .. 'ñ'
end end
elseif k == key.BACKSLASH then elseif k == key.BACKSLASH then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. 'Ç' me.command = me.command .. 'Ç'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '}' me.command = me.command .. '}'
else else
console.command = console.command .. 'ç' me.command = me.command .. 'ç'
end end
elseif k == key.RIGHTBRACKET then elseif k == key.RIGHTBRACKET then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '*' me.command = me.command .. '*'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ']' me.command = me.command .. ']'
else else
console.command = console.command .. '+' me.command = me.command .. '+'
end end
elseif k == key.LEFTBRACKET then elseif k == key.LEFTBRACKET then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '^' me.command = me.command .. '^'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. '[' me.command = me.command .. '['
else else
console.command = console.command .. '`' me.command = me.command .. '`'
end end
elseif k == key.NONUSBACKSLASH then elseif k == key.NONUSBACKSLASH then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '>' me.command = me.command .. '>'
elseif key.down(key.RALT) then elseif key.down(key.RALT) then
console.command = console.command .. ' ' me.command = me.command .. ' '
else else
console.command = console.command .. '<' me.command = me.command .. '<'
end end
elseif k == key.MINUS then elseif k == key.MINUS then
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
console.command = console.command .. '?' me.command = me.command .. '?'
else else
console.command = console.command .. '\'' me.command = me.command .. '\''
end end
elseif k == key.SPACE then elseif k == key.SPACE then
console.command = console.command .. ' ' me.command = me.command .. ' '
elseif k == key.BACKSPACE then elseif k == key.BACKSPACE then
console.command = console.command:sub(1, #console.command - 1) me.command = me.command:sub(1, #me.command - 1)
elseif k == key.TAB then elseif k == key.TAB then
local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) local sufix = me.autocomplete_list[me.autocomplete_index]:sub(#me.autocomplete_prefix+1)
console.command = console.command .. sufix me.command = me.command .. sufix
elseif k == key.RETURN then elseif k == key.RETURN then
table.insert(console.history, console.command) table.insert(me.history, me.command)
console.history_pos = #console.history+1 me.history_pos = #me.history+1
local f,err = load(console.command) local f,err = load(me.command)
if not f then if not f then
print("Error al compilar:", err) print("Error al compilar:", err)
else else
@@ -338,26 +339,24 @@ console = {
end end
if should_update then if should_update then
local a, b = split_by_last_separator(console.command) local a, b = split_by_last_separator(me.command)
if b ~= "" then if b ~= "" then
local ba, bb = split_by_last_dot(b) local ba, bb = split_by_last_dot(b)
console.autocomplete_prefix = bb me.autocomplete_prefix = bb
if ba ~= "" then if ba ~= "" then
console.autocomplete_list = entries_starting_with(bb, get_by_path(ba)) me.autocomplete_list = entries_starting_with(bb, get_by_path(ba))
--print(bb..":"..ba) --print(bb..":"..ba)
--print(#console.autocomplete_list) --print(#me.autocomplete_list)
else else
console.autocomplete_list = entries_starting_with(bb, _G) me.autocomplete_list = entries_starting_with(bb, _G)
--print(bb..":".."golbal") --print(bb..":".."golbal")
--print(#console.autocomplete_list) --print(#me.autocomplete_list)
end end
else else
console.autocomplete_prefix = "" me.autocomplete_prefix = ""
console.autocomplete_list = entries_starting_with("", _G) me.autocomplete_list = entries_starting_with("", _G)
--print("<buit>"..":".."golbal") --print("<buit>"..":".."golbal")
--print(#console.autocomplete_list) --print(#me.autocomplete_list)
end end
end end
end, end
}
File renamed without changes.
File renamed without changes.
View File
File renamed without changes.
File renamed without changes.
File renamed without changes.
View File
File renamed without changes.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

File renamed without changes.
File renamed without changes.
File renamed without changes.
+12 -55
View File
@@ -1,57 +1,14 @@
items = { items = {
[1] = { { name="mummy", label="momia", visual={x=0, y=24, w=16, h=16} },
name="mummy", { name="coin", label="moneda", visual={x=0, y=40, w=8, h=8} },
label="momia", { name="torxa", label="torxa", visual={x=0, y=48, w=8, h=16} },
visual = {x=0,y=24,w=16,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} },
[2] = { { name="clau roja", label="clau", visual={x=32, y=48, w=16, h=8} },
name="coin", { name="clau blava", label="clau", visual={x=32, y=56, w=16, h=8} },
label="moneda", { name="porta verda", label="porta", visual={x=48, y=48, w=8, h=16} },
visual = {x=0,y=40,w=8,h=8} { 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} },
[3] = { { name="porta blava", label="porta", visual={x=72, y=48, w=8, h=16} },
name="torxa", { name="sucubo", label="sucubo", visual={x=0, y=64, w=16, h=16} },
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}
},
} }
+3 -3
View File
@@ -8,10 +8,10 @@ require "palfade"
function reload_textures() function reload_textures()
if surf_sprites then surf.free(surf_sprites) end 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 if surf_tiles then surf.free(surf_tiles) end
surf_tiles = surf.load("tiles.gif") surf_tiles = surf.load("gfx/tiles.gif")
palfade.original = pal.load("tiles.gif") palfade.original = pal.load("gfx/tiles.gif")
pal.set(palfade.original) pal.set(palfade.original)
end end
File renamed without changes.
File renamed without changes.
Binary file not shown.
+32 -86
View File
@@ -1,29 +1,29 @@
require "popup"
require "ui" require "ui"
menu = { menu = {
hidden = true, hidden = true,
pos_y = 0, pos_y = 0,
selected = 1, selected = 1,
} local me = menu
draw = function() function me.draw()
actions = { actions = {
function() editor.play() menu.close() end, function() editor.play() me.close() end,
function() rooms.save() editor.modified=false menu.close() end, function() rooms.save() editor.modified=false me.close() end,
function() editor.quit() menu.close() end, function() editor.quit() me.close() end,
function() editor.layer=LAYER_FOREGROUND menu.close() end, function() editor.layer=LAYER_FOREGROUND me.close() end,
function() editor.layer=LAYER_BACKGROUND menu.close() end, function() editor.layer=LAYER_BACKGROUND me.close() end,
function() editor.layer=LAYER_ITEMS menu.close() end, function() editor.layer=LAYER_ITEMS me.close() end,
function() rooms.toggle_visibility(LAYER_FOREGROUND) end, function() rooms.toggle_visibility(LAYER_FOREGROUND) end,
function() rooms.toggle_visibility(LAYER_BACKGROUND) end, function() rooms.toggle_visibility(LAYER_BACKGROUND) end,
function() rooms.toggle_visibility(LAYER_SHADOWS) end, function() rooms.toggle_visibility(LAYER_SHADOWS) end,
function() rooms.toggle_visibility(LAYER_ITEMS) end function() rooms.toggle_visibility(LAYER_ITEMS) end
} }
local sel = menu.selected local sel = me.selected
view.origin(0,menu.pos_y) view.origin(0,me.pos_y)
view.clip() view.clip()
local y = menu.pos_y local y = me.pos_y
draw.rrectf(1,0,8,8,1,21) draw.rrectf(1,0,8,8,1,21)
draw.rrectf(1,-1,8,8,1,6) draw.rrectf(1,-1,8,8,1,6)
draw.hline(3,1,6,21) draw.hline(3,1,6,21)
@@ -33,7 +33,7 @@ menu = {
if y<=0 then return end if y<=0 then return end
view.origin(0,menu.pos_y-24) view.origin(0,me.pos_y-24)
draw.rectf(0,0,160,24,6) draw.rectf(0,0,160,24,6)
ui.pushbutton("PLAY",1,3,16,13,10,actions[1], sel==1) ui.pushbutton("PLAY",1,3,16,13,10,actions[1], sel==1)
@@ -59,86 +59,32 @@ menu = {
local tab = key.press(key.TAB) local tab = key.press(key.TAB)
if key.press(key.ESCAPE) then if key.press(key.ESCAPE) then
menu.toggle() me.toggle()
elseif key.press(key.LEFT) or (tab and key.down(key.LSHIFT)) then elseif key.press(key.LEFT) or (tab and key.down(key.LSHIFT)) then
menu.selected=menu.selected-1 me.selected=me.selected-1
if menu.selected < 1 then menu.selected = 10 end if me.selected < 1 then me.selected = 10 end
elseif key.press(key.RIGHT) or (tab and not key.down(key.LSHIFT)) then elseif key.press(key.RIGHT) or (tab and not key.down(key.LSHIFT)) then
menu.selected=menu.selected+1 me.selected=me.selected+1
if menu.selected > 10 then menu.selected = 1 end if me.selected > 10 then me.selected = 1 end
elseif key.press(key.RETURN) or key.press(key.SPACE) then elseif key.press(key.RETURN) or key.press(key.SPACE) then
actions[menu.selected]() actions[me.selected]()
end end
end, end
toggle = function() function me.toggle()
if menu.hidden then if me.hidden then
menu.hidden = false me.hidden = false
menu.selected = 1 me.selected = 1
tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end)
else else
menu.hidden = true me.hidden = true
tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end)
end end
end, end
close = function() function me.close()
if not menu.hidden then if not me.hidden then
menu.hidden = true me.hidden = true
tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)me.pos_y=value end)
end 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
}
+30 -47
View File
@@ -8,76 +8,59 @@ msgbox = {
selected = 0, selected = 0,
w = 100, w = 100,
h = 50, h = 50,
} local me = msgbox
show = function(title, text, buttons, default) function me.show(title, text, buttons, default)
msgbox.selected = default or 1 me.selected = default or 1
msgbox.title = title me.title = title
msgbox.text = text me.text = text
msgbox.buttons = buttons me.buttons = buttons
msgbox.w = 0 me.w = 0
for i,v in ipairs(msgbox.text) do for i,v in ipairs(me.text) do
local width = #v*4+8 local width = #v*4+8
if width > msgbox.w then msgbox.w = width end if width > me.w then me.w = width end
end end
msgbox.h = #msgbox.text*6+35 me.h = #me.text*6+35
app.push(msgbox.update) app.push(me.update)
end, end
update = function() function me.update()
local top = (160-msgbox.w)//2 local top = (160-me.w)//2
local left = (104-msgbox.h)//2 local left = (104-me.h)//2
view.clip(top, left, msgbox.w, msgbox.h) view.clip(top, left, me.w, me.h)
view.origin(top, left) view.origin(top, left)
--draw.outset(0, 0, msgbox.w, msgbox.h) draw.rrectf(0,0,me.w, me.h,4,27)
draw.rrectf(0,0,msgbox.w, msgbox.h,4,27)
--draw.rectf(1,1,msgbox.w-2, 7, 21) --draw.rectf(1,1,me.w-2, 7, 21)
draw.text(msgbox.title, 5, 4, 4) draw.text(me.title, 5, 4, 4)
local y = 14 local y = 14
for i,v in ipairs(msgbox.text) do for i,v in ipairs(me.text) do
draw.text(v, 5, y, 21) draw.text(v, 5, y, 21)
y = y + 6 y = y + 6
end end
local mx, my = mouse.pos() local mx, my = mouse.pos()
local x = msgbox.w - 35 local x = me.w - 35
y = msgbox.h - 12 y = me.h - 12
for i,v in ipairs(msgbox.buttons) do for i,v in ipairs(me.buttons) do
ui.pushbutton(v[1],x,y,7,22,21,v[2],msgbox.selected==i) ui.pushbutton(v[1],x,y,7,22,21,v[2],me.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 x = x - 34
end end
if key.press(key.ESCAPE) then if key.press(key.ESCAPE) then
app.pop() app.pop()
elseif key.press(key.RIGHT) then elseif key.press(key.RIGHT) then
msgbox.selected=msgbox.selected-1 me.selected=me.selected-1
if msgbox.selected==0 then msgbox.selected = #msgbox.buttons end if me.selected==0 then me.selected = #me.buttons end
elseif key.press(key.LEFT) then elseif key.press(key.LEFT) then
msgbox.selected=msgbox.selected+1 me.selected=me.selected+1
if msgbox.selected>#msgbox.buttons then msgbox.selected = 1 end if me.selected>#me.buttons then me.selected = 1 end
elseif key.press(key.RETURN) then elseif key.press(key.RETURN) then
msgbox.buttons[msgbox.selected][2]() me.buttons[me.selected][2]()
end end
end end
}
+32 -38
View File
@@ -1,69 +1,63 @@
palfade = { palfade = {
original = {}, original = {},
reddish = {}, reddish = {},
} local me = palfade
init = function () function me.init()
for i=1,32 do for i=1,32 do
palfade.reddish[i] = {r=palfade.original[i].r, g=palfade.original[i].g, b=palfade.original[i].b} me.reddish[i] = {r=me.original[i].r, g=me.original[i].g, b=me.original[i].b}
end end
end, end
luminance = function(r, g, b) function luminance(r, g, b)
return (0.2126*r + 0.7152*g + 0.0722*b)/255 return (0.2126*r + 0.7152*g + 0.0722*b)/255
end, end
reddish_limit = function(r, g, b) function me.reddish_limit(r, g, b)
local t = palfade.luminance(r, g, b) / 255 local t = me.luminance(r, g, b) / 255
local R = 255 * t local R = 255 * t
local G = g * (1 - t) local G = g * (1 - t)
local B = b * (1 - t) local B = b * (1 - t)
return R, G, B return R, G, B
end, end
fade_reddish_color = function(r, g, b, f) function me.fade_reddish_color(r, g, b, f)
--local Rr, Gr, Br = palfade.reddish_limit(r, g, b) local ff = math.min(1, f+me.luminance(r,g,b))
local ff = math.min(1, f+palfade.luminance(r,g,b)) local R = math.floor(r*ff)
local R = math.floor(r*ff)--math.floor(r + (Rr - r) * f) local G = math.floor(g*f)
local G = math.floor(g*f)--math.floor(g + (Gr - g) * f) local B = math.floor(b*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 return R, G, B
end, end
fade_reddish = function(f) function me.fade_reddish(f)
for i=1,32 do 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) local r, g, b = me.fade_reddish_color(me.original[i].r, me.original[i].g, me.original[i].b, f)
palfade.reddish[i].r, palfade.reddish[i].g, palfade.reddish[i].b = r, g, b me.reddish[i].r, me.reddish[i].g, me.reddish[i].b = r, g, b
pal.color(i-1,r,g,b) pal.color(i-1,r,g,b)
end end
end, end
fade_red = function(f) function me.fade_red(f)
for i=1,32 do for i=1,32 do
local r = math.floor(palfade.reddish[i].r + (255-palfade.reddish[i].r)*f) local r = math.floor(me.reddish[i].r + (255-me.reddish[i].r)*f)
local g = math.floor(palfade.reddish[i].g - (palfade.reddish[i].g)*f) local g = math.floor(me.reddish[i].g - (me.reddish[i].g)*f)
local b = math.floor(palfade.reddish[i].b - (palfade.reddish[i].b)*f) local b = math.floor(me.reddish[i].b - (me.reddish[i].b)*f)
pal.color(i-1,r,g,b) pal.color(i-1,r,g,b)
end end
end
end, function me.fade_white(f)
fade_white = function(f)
for i=1,32 do for i=1,32 do
local r = math.floor(palfade.reddish[i].r + (255-palfade.reddish[i].r)*f) local r = math.floor(me.reddish[i].r + (255-me.reddish[i].r)*f)
local g = math.floor(palfade.reddish[i].g + (255-palfade.reddish[i].g)*f) local g = math.floor(me.reddish[i].g + (255-me.reddish[i].g)*f)
local b = math.floor(palfade.reddish[i].b + (255-palfade.reddish[i].b)*f) local b = math.floor(me.reddish[i].b + (255-me.reddish[i].b)*f)
pal.color(i-1,r,g,b) pal.color(i-1,r,g,b)
end end
end, end
restore = function() function me.restore()
pal.set(palfade.original) pal.set(me.original)
end end
}
-52
View File
@@ -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
}
+27 -32
View File
@@ -15,12 +15,13 @@ rooms = {
surf_original_items = nil, surf_original_items = nil,
visibility = LAYER_ALL, visibility = LAYER_ALL,
pos = {x=0, y=4*13}, pos = {x=0, y=4*13},
}
current = function() function rooms.current()
return (rooms.pos.x//20) + (rooms.pos.y//13) * 8 return (rooms.pos.x//20) + (rooms.pos.y//13) * 8
end, end
convert = function(src) function rooms.convert(src)
local dst = surf.new(20*8,13*8) local dst = surf.new(20*8,13*8)
surf.source(src) surf.source(src)
surf.target(dst) surf.target(dst)
@@ -35,45 +36,45 @@ rooms = {
end end
end end
return dst return dst
end, end
reload = function() function rooms.reload()
if rooms.surf_background ~= nil then surf.free(rooms.surf_background) end 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.load("maps/rooms_background"..ROOM_FILE_EXT)
--rooms.surf_background = surf.new(20*8,13*8) --rooms.surf_background = surf.new(20*8,13*8)
--rooms.surf_background = rooms.convert(surf.load("rooms_background"..ROOM_FILE_EXT)) --rooms.surf_background = rooms.convert(surf.load("rooms_background"..ROOM_FILE_EXT))
if rooms.surf_foreground ~= nil then surf.free(rooms.surf_foreground) end 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.load("maps/rooms_foreground"..ROOM_FILE_EXT)
--rooms.surf_foreground = surf.new(20*8,12*8) --rooms.surf_foreground = surf.new(20*8,12*8)
--rooms.surf_foreground = rooms.convert(surf.load("rooms_foreground"..ROOM_FILE_EXT)) --rooms.surf_foreground = rooms.convert(surf.load("rooms_foreground"..ROOM_FILE_EXT))
if rooms.surf_items ~= nil then surf.free(rooms.surf_items) end 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.load("maps/rooms_items"..ROOM_FILE_EXT)
--rooms.surf_items = surf.new(20*8,12*8) --rooms.surf_items = surf.new(20*8,12*8)
--rooms.surf_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT)) --rooms.surf_items = rooms.convert(surf.load("rooms_items"..ROOM_FILE_EXT))
end, end
init = function() function rooms.init()
rooms.pos.x, rooms.pos.y = 0,4*13 rooms.pos.x, rooms.pos.y = 0,4*13
rooms.reload() rooms.reload()
sprites.init() sprites.init()
end, end
save = function() function rooms.save()
local p = {} local p = {}
for i=0,255 do p[i] = {r=i,g=i,b=i} end 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_background, "data/maps/rooms_background"..ROOM_FILE_EXT, p)
surf.save(rooms.surf_foreground, "data/rooms_foreground"..ROOM_FILE_EXT, p) surf.save(rooms.surf_foreground, "data/maps/rooms_foreground"..ROOM_FILE_EXT, p)
surf.save(rooms.surf_items, "data/rooms_items"..ROOM_FILE_EXT, p) surf.save(rooms.surf_items, "data/maps/rooms_items"..ROOM_FILE_EXT, p)
editor.modified = false editor.modified = false
end, end
is_outside = function(x, y) 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 return x < rooms.pos.x or y < rooms.pos.y or x > rooms.pos.x + 20 or y > rooms.pos.y + 13
end, end
draw = function() function rooms.draw()
-- Retallem la pantalla a la zona de joc -- Retallem la pantalla a la zona de joc
--view.clip(0,8,160,96) --view.clip(0,8,160,96)
@@ -121,30 +122,24 @@ rooms = {
-- Pintem la rejilla -- Pintem la rejilla
--for y=0,12 do draw.line(0,y*8, 160, y*8, 27) end --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 --for x=0,20 do draw.line(x*8, 0, x*8, 104, 27) end
end, end
is_visible = function(layer) function rooms.is_visible(layer)
return (app.update==game.update) or (rooms.visibility & layer == layer) return (app.update==game.update) or (rooms.visibility & layer == layer)
end, end
set_visibility = function(layer, visibility) function rooms.set_visibility(layer, visibility)
if visibility then if visibility then
rooms.visibility = rooms.visibility | layer rooms.visibility = rooms.visibility | layer
else else
rooms.visibility = rooms.visibility & ~layer rooms.visibility = rooms.visibility & ~layer
end end
end, end
toggle_visibility = function(layer) function rooms.toggle_visibility(layer)
if rooms.visibility & layer == layer then if rooms.visibility & layer == layer then
rooms.visibility = rooms.visibility & ~layer rooms.visibility = rooms.visibility & ~layer
else else
rooms.visibility = rooms.visibility | layer rooms.visibility = rooms.visibility | layer
end end
end, end
peiv = function()
pal.color(1, 1, 1, 1)
return "HOLA OTHER UNIT"
end,
}
+13 -14
View File
@@ -3,25 +3,24 @@ score = {
color = 28, color = 28,
zoom = 1, zoom = 1,
surf = nil, surf = nil,
} local me = score
init = function() function me.init()
score.points = 0 me.points = 0
score.surf = surf.load("sprites.gif") me.surf = surf.load("gfx/sprites.gif")
end, end
draw = function() function me.draw()
draw.rectf(0,0,160,8,1) draw.rectf(0,0,160,8,1)
draw.text(string.format("%03d", score.points),1,1,score.color) draw.text(string.format("%03d", me.points),1,1,me.color)
surf.source(score.surf) surf.source(me.surf)
if sprites.hero.keys["verda"] then draw.surf(16,48,16,8, 32,-1) end 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["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["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 if sprites.hero.keys["blava"] then draw.surf(32,56,16,8, 32,-1) end
end, end
inc = function(value) function me.inc(value)
--print("score.inc()") me.points = me.points + value
score.points = score.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)
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
end
}
+38 -2
View File
@@ -54,7 +54,7 @@ sprites = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = false, flipped = false,
surf = surf.load("morcus.gif"), surf = surf.load("gfx/morcus.gif"),
animation = "hero_stand", animation = "hero_stand",
ia = sprites.update_hero, ia = sprites.update_hero,
state = templates.ALIVE, state = templates.ALIVE,
@@ -155,7 +155,7 @@ sprites = {
if sprites.hero.lives == 0 then if sprites.hero.lives == 0 then
sprites.hero.state = templates.DEAD 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.set_animation(sprites.hero, "mummy_dying")
sprites.hero.jumping = 0 sprites.hero.jumping = 0
sprites.hero.cooldown = 120 sprites.hero.cooldown = 120
@@ -370,6 +370,42 @@ sprites = {
end end
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() update_hero = function()
if sprites.hero.state == templates.DEAD then if sprites.hero.state == templates.DEAD then
+33 -16
View File
@@ -3,8 +3,9 @@ templates = {
DYING = 1, DYING = 1,
DEAD = 2, DEAD = 2,
RESURRECTING = 3, RESURRECTING = 3,
} local me = templates
create = function(type, options) function me.create(type, options)
local sprite local sprite
local key, value = type:match("^(%S+)%s*(.*)$") local key, value = type:match("^(%S+)%s*(.*)$")
@@ -17,9 +18,9 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load("mummy.gif"), surf = surf.load("gfx/mummy.gif"),
animation = "mummy_walk", animation = "mummy_walk",
state = templates.ALIVE, state = me.ALIVE,
enemy = true, enemy = true,
room = options.room, room = options.room,
ia = sprites.update_mummy ia = sprites.update_mummy
@@ -33,7 +34,7 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load("morcus.gif"), surf = surf.load("gfx/morcus.gif"),
animation = "bullet", animation = "bullet",
ia = sprites.update_bullet ia = sprites.update_bullet
} }
@@ -46,9 +47,9 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load("misc.gif"), surf = surf.load("gfx/misc.gif"),
animation = "coin", animation = "coin",
state = templates.ALIVE, state = me.ALIVE,
timer = 0, timer = 0,
light = 15, light = 15,
light_ox = 4, light_ox = 4,
@@ -64,9 +65,9 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load("misc.gif"), surf = surf.load("gfx/misc.gif"),
animation = "brick", animation = "brick",
state = templates.ALIVE, state = me.ALIVE,
timeout = 10, timeout = 10,
ia = sprites.update_brick ia = sprites.update_brick
} }
@@ -79,9 +80,9 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load("torxa.gif"), surf = surf.load("gfx/torxa.gif"),
animation = "torxa", animation = "torxa",
state = templates.ALIVE, state = me.ALIVE,
light = 30, light = 30,
light_ox = 4, light_ox = 4,
light_oy = 4, light_oy = 4,
@@ -98,9 +99,9 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load(value..".gif"), surf = surf.load("gfx/"..value..".gif"),
animation = "clau", animation = "clau",
state = templates.ALIVE, state = me.ALIVE,
light = 15, light = 15,
light_ox = 7, light_ox = 7,
light_oy = 4, light_oy = 4,
@@ -116,16 +117,32 @@ templates = {
current_frame = 1, current_frame = 1,
current_wait = 1, current_wait = 1,
flipped = options.flipped, flipped = options.flipped,
surf = surf.load(value..".gif"), surf = surf.load("gfx/"..value..".gif"),
animation = "porta", animation = "porta",
state = templates.ALIVE, state = me.ALIVE,
ia = sprites.update_porta 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 else
error("Template not recognized") error("Template not recognized")
end end
--sprite.room = rooms.current() --sprite.room = rooms.current()
print("creat sprite de tipus "..type) print("creat sprite de tipus "..type)
return sprite return sprite
end, end
}
+57 -57
View File
@@ -34,59 +34,60 @@ local function bounceOut(t)
end end
end end
easing = { easing = {} local me = easing
linear = function(t) return t end,
-- Sine function me.linear(t) return t end
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,
-- Quad -- Sine
easeInQuad = function(t) return t * t end, function me.easeInSine(t) return 1 - cos((t * pi) / 2) end
easeOutQuad = function(t) return 1 - (1 - t) * (1 - t) end, function me.easeOutSine(t) return sin((t * pi) / 2) end
easeInOutQuad = function(t) function me.easeInOutSine(t) return -(cos(pi * t) - 1) / 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 if t < 0.5 then return 2 * t * t end
return 1 - ((-2 * t + 2)^2) / 2 return 1 - ((-2 * t + 2)^2) / 2
end, end
-- Cubic -- Cubic
easeInCubic = function(t) return t * t * t end, function me.easeInCubic(t) return t * t * t end
easeOutCubic = function(t) return 1 - ((1 - t)^3) end, function me.easeOutCubic(t) return 1 - ((1 - t)^3) end
easeInOutCubic = function(t) function me.easeInOutCubic(t)
if t < 0.5 then return 4 * t * t * t end if t < 0.5 then return 4 * t * t * t end
return 1 - ((-2 * t + 2)^3) / 2 return 1 - ((-2 * t + 2)^3) / 2
end, end
-- Expo -- Expo
easeInExpo = function(t) return (t == 0) and 0 or (2^(10 * t - 10)) end, function me.easeInExpo(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, function me.easeOutExpo(t) return (t == 1) and 1 or 1 - (2^(-10 * t)) end
easeInOutExpo = function(t) function me.easeInOutExpo(t)
if t == 0 then return 0 end if t == 0 then return 0 end
if t == 1 then return 1 end if t == 1 then return 1 end
if t < 0.5 then return (2^(20 * t - 10)) / 2 end if t < 0.5 then return (2^(20 * t - 10)) / 2 end
return (2 - (2^(-20 * t + 10))) / 2 return (2 - (2^(-20 * t + 10))) / 2
end, end
-- Back (overshoot) -- Back (overshoot)
easeInBack = function(t) return backIn(t) end, function me.easeInBack(t) return backIn(t) end
easeOutBack = function(t) return backOut(t) end, function me.easeOutBack(t) return backOut(t) end
easeInOutBack = function(t) return backInOut(t) end, function me.easeInOutBack(t) return backInOut(t) end
-- Elastic -- Elastic
easeInElastic = function(t) function me.easeInElastic(t)
if t == 0 then return 0 end if t == 0 then return 0 end
if t == 1 then return 1 end if t == 1 then return 1 end
local c4 = (2 * pi) / 3 local c4 = (2 * pi) / 3
return -(2^(10 * t - 10)) * sin((t * 10 - 10.75) * c4) return -(2^(10 * t - 10)) * sin((t * 10 - 10.75) * c4)
end, end
easeOutElastic = function(t) function me.easeOutElastic(t)
if t == 0 then return 0 end if t == 0 then return 0 end
if t == 1 then return 1 end if t == 1 then return 1 end
local c4 = (2 * pi) / 3 local c4 = (2 * pi) / 3
return (2^(-10 * t)) * sin((t * 10 - 0.75) * c4) + 1 return (2^(-10 * t)) * sin((t * 10 - 0.75) * c4) + 1
end, end
easeInOutElastic = function(t) function me.easeInOutElastic(t)
if t == 0 then return 0 end if t == 0 then return 0 end
if t == 1 then return 1 end if t == 1 then return 1 end
local c5 = (2 * pi) / 4.5 local c5 = (2 * pi) / 4.5
@@ -94,22 +95,22 @@ easing = {
return -((2^(20 * t - 10)) * sin((20 * t - 11.125) * c5)) / 2 return -((2^(20 * t - 10)) * sin((20 * t - 11.125) * c5)) / 2
end end
return ((2^(-20 * t + 10)) * sin((20 * t - 11.125) * c5)) / 2 + 1 return ((2^(-20 * t + 10)) * sin((20 * t - 11.125) * c5)) / 2 + 1
end, end
-- Bounce -- Bounce
easeInBounce = function(t) return 1 - bounceOut(1 - t) end, function me.easeInBounce(t) return 1 - bounceOut(1 - t) end
easeOutBounce = function(t) return bounceOut(t) end, function me.easeOutBounce(t) return bounceOut(t) end
easeInOutBounce = function(t) function me.easeInOutBounce(t)
if t < 0.5 then return (1 - bounceOut(1 - 2 * t)) / 2 end if t < 0.5 then return (1 - bounceOut(1 - 2 * t)) / 2 end
return (1 + bounceOut(2 * t - 1)) / 2 return (1 + bounceOut(2 * t - 1)) / 2
end, end
}
tweening = { tweening = {
list = {}, list = {},
} me = tweening
add = function(from, to, duration, easingFun, callback) function me.add(from, to, duration, easingFun, callback)
local tween = { local tween = {
from = from, from = from,
to = to, to = to,
@@ -118,16 +119,16 @@ tweening = {
callback = callback, callback = callback,
t = 0, t = 0,
} }
tweening.list[#tweening.list + 1] = tween me.list[#me.list + 1] = tween
return tween return tween
end, end
update = function(dt) function me.update(dt)
if #tweening.list==0 then return end if #me.list==0 then return end
-- iterate backwards so we can remove finished tweens safely -- iterate backwards so we can remove finished tweens safely
for i = #tweening.list, 1, -1 do for i = #me.list, 1, -1 do
local tw = tweening.list[i] local tw = me.list[i]
tw.t = tw.t + (dt or 0) tw.t = tw.t + (dt or 0)
local progress = tw.t / tw.duration local progress = tw.t / tw.duration
if progress >= 1 then if progress >= 1 then
@@ -137,7 +138,7 @@ tweening = {
-- callback(value, normalizedProgress, finished) -- callback(value, normalizedProgress, finished)
tw.callback(value, 1, true) tw.callback(value, 1, true)
end end
table.remove(tweening.list, i) table.remove(me.list, i)
else else
-- in progress -- in progress
local alpha = tw.easing(progress) local alpha = tw.easing(progress)
@@ -145,20 +146,19 @@ tweening = {
if tw.callback then tw.callback(value, progress, false) end if tw.callback then tw.callback(value, progress, false) end
end end
end end
end, end
clear = function() function me.clear()
for i = #tweening.list, 1, -1 do table.remove(tweening.list, i) end for i = #me.list, 1, -1 do table.remove(me.list, i) end
end, end
-- Optional helper: cancel a specific tween (pass the tween returned by add) -- Optional helper: cancel a specific tween (pass the tween returned by add)
cancel = function(tween) function me.cancel(tween)
for i = #tweening.list, 1, -1 do for i = #me.list, 1, -1 do
if tweening.list[i] == tween then if me.list[i] == tween then
table.remove(tweening.list, i) table.remove(me.list, i)
return true return true
end end
end end
return false return false
end end
}
+5 -22
View File
@@ -1,5 +1,6 @@
ui = { ui = {}
pushbutton = function(label,x,y,h,col1,col2,callback,selected)
function ui.pushbutton(label,x,y,h,col1,col2,callback,selected)
local size = (#label*4)-1+4 local size = (#label*4)-1+4
local text_y = (h-5)//2 local text_y = (h-5)//2
local button_h=0 local button_h=0
@@ -14,9 +15,9 @@ ui = {
if selected then if selected then
draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1) draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1)
end end
end, end
togglebutton = function(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected) function ui.togglebutton(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected)
local size = (#label*4)-1+4 local size = (#label*4)-1+4
local text_y = (h-5)//2 local text_y = (h-5)//2
local bh=0 local bh=0
@@ -36,22 +37,4 @@ ui = {
if selected then if selected then
draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1) draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1)
end 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)
end
function draw.inset(x, y, w, h)
draw.rectf(x, y, w, h, 23)
w,h = w+x,h+y
draw.hline(x, y, w-1,16)
draw.vline(x, y, h-1,16)
draw.hline(x, h-1, w-1,28)
draw.vline(w-1, y, h-1,28)
end end
+7 -9
View File
@@ -1,6 +1,6 @@
util={ util={}
inside = function(x, y, rectangle) function util.inside(x, y, rectangle)
if x >= rectangle[1] and if x >= rectangle[1] and
y >= rectangle[2] and y >= rectangle[2] and
x < rectangle[3]+rectangle[1] and x < rectangle[3]+rectangle[1] and
@@ -9,18 +9,16 @@ util={
else else
return false return false
end end
end, end
aabb = function(sprite) function util.aabb(sprite)
local x = sprite.pos.x + sprite.bbo.left local x = sprite.pos.x + sprite.bbo.left
local y = sprite.pos.y + sprite.bbo.top local y = sprite.pos.y + sprite.bbo.top
local w = sprite.size.w - sprite.bbo.right - sprite.bbo.left local w = sprite.size.w - sprite.bbo.right - sprite.bbo.left
local h = sprite.size.h - sprite.bbo.bottom - sprite.bbo.top local h = sprite.size.h - sprite.bbo.bottom - sprite.bbo.top
return x, y, w, h return x, y, w, h
end, end
check_aabb_collision = function(x1,y1,w1,h1, x2,y2,w2,h2) 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 ) return ( x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2 )
end end
}