- Primera pasada de reorganització

This commit is contained in:
2026-03-12 17:30:56 +01:00
parent 8f185fa47c
commit 6c5d7a305a
30 changed files with 965 additions and 1096 deletions

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 },
}
},
} }

View File

@@ -1,16 +1,15 @@
app = { app = {
update = nil, update = nil,
stack = {}, stack = {},
push = function(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.push(func)
table.insert(app.stack, app.update)
app.update = func
end
function app.pop()
if #app.stack > 0 then
app.update = table.remove(app.stack)
end
end

View File

@@ -73,291 +73,290 @@ 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()
return return
end end
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
end
end
local k = key.press()
if k ~= key.UNKNOWN then
should_update = true 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
end
if should_update then local k = key.press()
local a, b = split_by_last_separator(console.command) if k ~= key.UNKNOWN then
if b ~= "" then should_update = true
local ba, bb = split_by_last_dot(b) if k >= key.A and k <= key.Z then
console.autocomplete_prefix = bb if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
if ba ~= "" then me.command = me.command .. string.char(k+61)
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
else else
console.autocomplete_prefix = "" me.command = me.command .. string.char(k+93)
console.autocomplete_list = entries_starting_with("", _G) end
--print("<buit>"..":".."golbal") elseif k == key.N0 then
--print(#console.autocomplete_list) 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
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

View File

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 234 B

View File

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 234 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 826 B

After

Width:  |  Height:  |  Size: 826 B

View File

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 654 B

View File

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
data/gfx/sucubo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 316 B

After

Width:  |  Height:  |  Size: 316 B

View File

Before

Width:  |  Height:  |  Size: 234 B

After

Width:  |  Height:  |  Size: 234 B

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}
},
} }

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

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -1,144 +1,90 @@
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)
draw.hline(3,3,6,21) draw.hline(3,3,6,21)
draw.hline(3,5,6,21) draw.hline(3,5,6,21)
if editor.modified then draw.rectf(6,0,2,2,8) end 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) 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)
ui.pushbutton("SAVE",22,3,7,22,21,actions[2], sel==2) ui.pushbutton("SAVE",22,3,7,22,21,actions[2], sel==2)
if editor.modified then draw.rectf(37,4,2,2,8) end 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("QUIT",22,12,7,12,5,actions[3], sel==3)
draw.rrect(44,6,29,14,3,21) draw.rrect(44,6,29,14,3,21)
draw.rectf(48,6,17,1,6) draw.rectf(48,6,17,1,6)
draw.text("EDIT",49,3,21) 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("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("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) 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.rrect(75,6,37,14,3,21)
draw.rectf(79,6,17,1,6) draw.rectf(79,6,17,1,6)
draw.text("SHOW",80,3,21) 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("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("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("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("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) 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
}

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
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
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

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,
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)
end 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

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
}

View File

@@ -15,136 +15,131 @@ 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)
for ry=0,7 do for ry=0,7 do
for rx=0,7 do for rx=0,7 do
for ty=0,11 do for ty=0,11 do
for tx=0,19 do for tx=0,19 do
surf.pixel(rx*20+tx, ry*13+ty, surf.pixel(rx*20+tx, ry*12+ty)) surf.pixel(rx*20+tx, ry*13+ty, surf.pixel(rx*20+tx, ry*12+ty))
end
end end
end end
end end
return dst end
end, return dst
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)
-- Movem la càmara a l'habitació on estem -- Movem la càmara a l'habitació on estem
view.origin(-rooms.pos.x*8,-rooms.pos.y*8) view.origin(-rooms.pos.x*8,-rooms.pos.y*8)
-- Pintem el background -- Pintem el background
surf.source(surf_tiles) surf.source(surf_tiles)
map.surf(rooms.surf_background) map.surf(rooms.surf_background)
if rooms.is_visible(LAYER_BACKGROUND) then if rooms.is_visible(LAYER_BACKGROUND) then
map.draw() map.draw()
else else
draw.rectf(0,0,160,96,1) draw.rectf(0,0,160,96,1)
end end
-- Movem 4x4 pixels la càmara per a pintar les sombres dels sprites i el foreground -- 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) view.origin(-rooms.pos.x*8+4,-rooms.pos.y*8+4)
-- Pintem el foreground de negre -- Pintem el foreground de negre
map.surf(rooms.surf_foreground) map.surf(rooms.surf_foreground)
pal.subpal(0,32,1) pal.subpal(0,32,1)
if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end if rooms.is_visible(LAYER_FOREGROUND | LAYER_SHADOWS) then map.draw() end
-- Pintem els sprites de negre -- Pintem els sprites de negre
if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then if rooms.is_visible(LAYER_SPRITES | LAYER_SHADOWS) then
sprites.draw(true) sprites.draw(true)
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17) --draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
end end
-- Movem la càmara al lloc que toca de nou, i tornem la paleta normal -- 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) view.origin(-rooms.pos.x*8,-rooms.pos.y*8)
pal.subpal() pal.subpal()
-- Pintem el foreground -- Pintem el foreground
surf.source(surf_tiles) surf.source(surf_tiles)
map.surf(rooms.surf_foreground) map.surf(rooms.surf_foreground)
if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end if rooms.is_visible(LAYER_FOREGROUND) then map.draw() end
-- Pintem els sprites -- Pintem els sprites
if rooms.is_visible(LAYER_SPRITES) then if rooms.is_visible(LAYER_SPRITES) then
sprites.draw() sprites.draw()
--draw.surf(0, 0, 16, 17, 20, 15, 16, 17) --draw.surf(0, 0, 16, 17, 20, 15, 16, 17)
end end
-- 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,
}

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
}

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

View File

@@ -3,129 +3,146 @@ 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*(.*)$")
if key == "mummy" then if key == "mummy" then
sprite = { sprite = {
type = key, type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=16,h=16 }, size = { w=16,h=16 },
bbo = { left=3, top=2, right=3, bottom=0 }, bbo = { left=3, top=2, right=3, bottom=0 },
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
} }
elseif key == "bullet" then elseif key == "bullet" then
sprite = { sprite = {
type = key, type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=4,h=3 }, size = { w=4,h=3 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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
} }
elseif key == "coin" then elseif key == "coin" then
sprite = { sprite = {
type = key, type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=8,h=8 }, size = { w=8,h=8 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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,
light_oy = 4, light_oy = 4,
ia = sprites.update_coin ia = sprites.update_coin
} }
elseif key == "brick" then elseif key == "brick" then
sprite = { sprite = {
type = key, type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=8,h=8 }, size = { w=8,h=8 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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
} }
elseif key == "torxa" then elseif key == "torxa" then
sprite = { sprite = {
type = key, type = key,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=8,h=16 }, size = { w=8,h=16 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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,
no_shadow = true, no_shadow = true,
ia = sprites.update_torxa ia = sprites.update_torxa
} }
elseif key == "clau" then elseif key == "clau" then
sprite = { sprite = {
type = key, type = key,
color = value, color = value,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=16,h=8 }, size = { w=16,h=8 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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,
ia = sprites.update_clau ia = sprites.update_clau
} }
elseif key == "porta" then elseif key == "porta" then
sprite = { sprite = {
type = key, type = key,
color = value, color = value,
pos = options.pos,--{ x=100, y=4*12*8+71 }, pos = options.pos,--{ x=100, y=4*12*8+71 },
size = { w=8,h=16 }, size = { w=8,h=16 },
bbo = { left=0, top=0, right=0, bottom=0 }, bbo = { left=0, top=0, right=0, bottom=0 },
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
} }
else elseif key == "sucubo" then
error("Template not recognized") sprite = {
end type = key,
--sprite.room = rooms.current() pos = options.pos,--{ x=100, y=4*12*8+71 },
print("creat sprite de tipus "..type) size = { w=16,h=16 },
return sprite bbo = { left=3, top=2, right=3, bottom=0 },
end, 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

View File

@@ -34,131 +34,131 @@ 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
if t < 0.5 then return 2 * t * t end
return 1 - ((-2 * t + 2)^2) / 2
end,
-- Cubic -- Quad
easeInCubic = function(t) return t * t * t end, function me.easeInQuad(t) return t * t end
easeOutCubic = function(t) return 1 - ((1 - t)^3) end, function me.easeOutQuad(t) return 1 - (1 - t) * (1 - t) end
easeInOutCubic = function(t) function me.easeInOutQuad(t)
if t < 0.5 then return 4 * t * t * t end if t < 0.5 then return 2 * t * t end
return 1 - ((-2 * t + 2)^3) / 2 return 1 - ((-2 * t + 2)^2) / 2
end, end
-- Expo -- Cubic
easeInExpo = function(t) return (t == 0) and 0 or (2^(10 * t - 10)) end, function me.easeInCubic(t) return t * t * t end
easeOutExpo = function(t) return (t == 1) and 1 or 1 - (2^(-10 * t)) end, function me.easeOutCubic(t) return 1 - ((1 - t)^3) end
easeInOutExpo = function(t) function me.easeInOutCubic(t)
if t == 0 then return 0 end if t < 0.5 then return 4 * t * t * t end
if t == 1 then return 1 end return 1 - ((-2 * t + 2)^3) / 2
if t < 0.5 then return (2^(20 * t - 10)) / 2 end end
return (2 - (2^(-20 * t + 10))) / 2
end,
-- Back (overshoot) -- Expo
easeInBack = function(t) return backIn(t) end, function me.easeInExpo(t) return (t == 0) and 0 or (2^(10 * t - 10)) end
easeOutBack = function(t) return backOut(t) end, function me.easeOutExpo(t) return (t == 1) and 1 or 1 - (2^(-10 * t)) end
easeInOutBack = function(t) return backInOut(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 -- Back (overshoot)
easeInElastic = function(t) function me.easeInBack(t) return backIn(t) end
if t == 0 then return 0 end function me.easeOutBack(t) return backOut(t) end
if t == 1 then return 1 end function me.easeInOutBack(t) return backInOut(t) 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,
-- Bounce -- Elastic
easeInBounce = function(t) return 1 - bounceOut(1 - t) end, function me.easeInElastic(t)
easeOutBounce = function(t) return bounceOut(t) end, if t == 0 then return 0 end
easeInOutBounce = function(t) if t == 1 then return 1 end
if t < 0.5 then return (1 - bounceOut(1 - 2 * t)) / 2 end local c4 = (2 * pi) / 3
return (1 + bounceOut(2 * t - 1)) / 2 return -(2^(10 * t - 10)) * sin((t * 10 - 10.75) * c4)
end, 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 = { 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,
duration = math.max(0.000001, duration or 0.001), duration = math.max(0.000001, duration or 0.001),
easing = easingFun, easing = easingFun,
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
-- finished: ensure final value, call callback with finished=true, remove -- finished: ensure final value, call callback with finished=true, remove
local value = tw.to local value = tw.to
if tw.callback then if tw.callback then
-- callback(value, normalizedProgress, finished) -- callback(value, normalizedProgress, finished)
tw.callback(value, 1, true) 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
end 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
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
} 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

View File

@@ -1,57 +1,40 @@
ui = { 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,
togglebutton = function(label,x,y,h,col1,col2,dis1,dis2,state,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 bh=0 local button_h=0
local mx, my = mouse.pos() local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then if mx>=x and mx<x+size and my>=y and my<y+h then
bh = mouse.down(mouse.LEFT) and -1 or 1 button_h = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end if mouse.press(mouse.LEFT) then callback() end
end end
if not state then draw.rrectf(x,y+1,size,h,1,col2)
col1,col2 = dis1,dis2 draw.rrectf(x,y-button_h,size,h,1,col1)
else draw.text(label,x+2,y+text_y-button_h,col2)
if bh>-1 then bh=bh-1 end if selected then
end draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1)
draw.rrectf(x,y+1,size,h,1,col2) end
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)
end end
function draw.inset(x, y, w, h) function ui.togglebutton(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected)
draw.rectf(x, y, w, h, 23) local size = (#label*4)-1+4
w,h = w+x,h+y local text_y = (h-5)//2
draw.hline(x, y, w-1,16) local bh=0
draw.vline(x, y, h-1,16) local mx, my = mouse.pos()
draw.hline(x, h-1, w-1,28) if mx>=x and mx<x+size and my>=y and my<y+h then
draw.vline(w-1, y, h-1,28) 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 end

View File

@@ -1,26 +1,24 @@
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
y < rectangle[4]+rectangle[2] then y < rectangle[4]+rectangle[2] then
return true return true
else else
return false 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 )
end 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