- 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
+965 -1096

No files matched your search

+15
View File
@@ -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 },
}
},
}
+10 -11
View File
@@ -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,
}
function app.pop()
if #app.stack > 0 then
app.update = table.remove(app.stack)
end
end
+272 -273
View File
@@ -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("<buit>"..":".."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,
}
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("<buit>"..":".."golbal")
--print(#me.autocomplete_list)
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.
+13 -56
View File
@@ -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}
},
}
{ 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} },
}
+3 -3
View File
@@ -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
File renamed without changes.
File renamed without changes.
Binary file not shown.
+73 -127
View File
@@ -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
}
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
+53 -70
View File
@@ -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
}
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
+57 -63
View File
@@ -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
}
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
-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
}
+103 -108
View File
@@ -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
+18 -19
View File
@@ -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
+38 -2
View File
@@ -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
+141 -124
View File
@@ -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,
}
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
+111 -111
View File
@@ -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
}
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
+37 -54
View File
@@ -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<x+size and my>=y and my<y+h then
button_h = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
draw.rrectf(x,y+1,size,h,1,col2)
draw.rrectf(x,y-button_h,size,h,1,col1)
draw.text(label,x+2,y+text_y-button_h,col2)
if selected then
draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1)
end
end,
ui = {}
togglebutton = function(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected)
local size = (#label*4)-1+4
local text_y = (h-5)//2
local bh=0
local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then
bh = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
if not state then
col1,col2 = dis1,dis2
else
if bh>-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<x+size and my>=y and my<y+h then
button_h = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
draw.rrectf(x,y+1,size,h,1,col2)
draw.rrectf(x,y-button_h,size,h,1,col1)
draw.text(label,x+2,y+text_y-button_h,col2)
if selected then
draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1)
end
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
function ui.togglebutton(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected)
local size = (#label*4)-1+4
local text_y = (h-5)//2
local bh=0
local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then
bh = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
if not state then
col1,col2 = dis1,dis2
else
if bh>-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
+21 -23
View File
@@ -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
}
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