- [NEW] Afegit cooldown entre dispar i dispar

- [NEW] mòdul console
- [NEW] mòdul tweening
- [NEW] mòdul palfade
This commit is contained in:
2026-02-24 18:59:28 +01:00
parent 12673f1dc4
commit 7ba7fc04d6
6 changed files with 506 additions and 4 deletions

247
data/console.lua Normal file
View File

@@ -0,0 +1,247 @@
console = {
command = "",
history = {},
history_pos = 0,
cursor = 50,
enable = function()
app.push(console.update)
console.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)
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 key.press(key.ESCAPE) then
app.pop()
return
end
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]
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]
end
end
local k = key.press()
if k ~= key.UNKNOWN then
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.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,
}

View File

@@ -1,3 +1,12 @@
require "palfade"
require "console"
require "tweening"
function test()
tweening.add(40, 100, 1, easing.easeOutCubic, function(value, progress, finished) sprites.hero.light = value end)
tweening.add(0, 1, 1, easing.easeOutCubic, function(value, progress, finished) palfade.fade_reddish(value) end)
end
game = { game = {
chg_adv = {x=0, y=0}, chg_adv = {x=0, y=0},
chg_step = 0, chg_step = 0,
@@ -10,6 +19,7 @@ game = {
light_strobe_value = 0, light_strobe_value = 0,
light_strobe_dir = 1, light_strobe_dir = 1,
water_counter = 0, water_counter = 0,
fade=0,
enable = function() enable = function()
if game.back_buf == 0 then if game.back_buf == 0 then
@@ -18,12 +28,23 @@ game = {
end end
app.update = game.update app.update = game.update
sys.beat(2) sys.beat(2)
palfade.init()
--palfade.fade_reddish(0.5)
--shader.enable(); --shader.enable();
end, end,
update = function() update = function()
tweening.update(sys.delta())
game.water_counter = game.water_counter + 0.05 game.water_counter = game.water_counter + 0.05
if game.fade>0 then
palfade.fade_red(game.fade)
game.fade = game.fade - 0.1
elseif game.fade<0 then
palfade.fade_red(0)
game.fade = 0
end
view.origin(0,0) view.origin(0,0)
surf.target(0) surf.target(0)
view.clip() view.clip()
@@ -41,6 +62,8 @@ game = {
if key.press(key.ESCAPE) or key.press(key.F9) then if key.press(key.ESCAPE) or key.press(key.F9) then
rooms.retrieve_original_items() rooms.retrieve_original_items()
editor.enable() editor.enable()
elseif key.press(key.GRAVE) then
console.enable()
end end
end, end,

View File

@@ -3,14 +3,16 @@ require "score"
require "rooms" require "rooms"
require "editor" require "editor"
require "game" require "game"
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("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("tiles.gif")
palfade.original = pal.load("tiles.gif")
pal.set(pal.load("tiles.gif")) pal.set(palfade.original)
end end
function mini.init() function mini.init()

60
data/palfade.lua Normal file
View File

@@ -0,0 +1,60 @@
palfade = {
original = {},
reddish = {},
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,
restore = function()
pal.set(palfade.original)
end
}

View File

@@ -61,6 +61,7 @@ sprites = {
light = 100, light = 100,
light_ox = 0, light_ox = 0,
light_oy = 0, light_oy = 0,
cooldown = 0,
stairs = false stairs = false
} }
--table.insert(sprites.list, templates.create("mummy", {pos={x=100, y=4*12*8+71},flipped=true})) --table.insert(sprites.list, templates.create("mummy", {pos={x=100, y=4*12*8+71},flipped=true}))
@@ -227,6 +228,10 @@ sprites = {
local anim = "hero_stand" local anim = "hero_stand"
local move_anim = "hero_walk" local move_anim = "hero_walk"
if sprites.hero.cooldown > 0 then
sprites.hero.cooldown = sprites.hero.cooldown - 1
end
if sprites.hero.shooting then if sprites.hero.shooting then
if sprites.hero.current_frame==3 then if sprites.hero.current_frame==3 then
sprites.hero.shooting = false sprites.hero.shooting = false
@@ -315,8 +320,9 @@ sprites = {
sprites.hero.jumping = 17 sprites.hero.jumping = 17
-- SI POLSA DISPAR... -- SI POLSA DISPAR...
elseif key.down(key.X) or pad.down(pad.B) then elseif (sprites.hero.cooldown==0) and (key.down(key.X) or pad.down(pad.B)) then
sprites.hero.shooting = true sprites.hero.shooting = true
sprites.hero.cooldown = 20
local x = sprites.hero.flipped and sprites.hero.pos.x+8 or sprites.hero.pos.x-8 local x = sprites.hero.flipped and sprites.hero.pos.x+8 or sprites.hero.pos.x-8
local bullet = templates.create("bullet", {pos={x=sprites.hero.pos.x, y=sprites.hero.pos.y+7}, flipped=sprites.hero.flipped}) local bullet = templates.create("bullet", {pos={x=sprites.hero.pos.x, y=sprites.hero.pos.y+7}, flipped=sprites.hero.flipped})
table.insert(sprites.list, bullet) table.insert(sprites.list, bullet)

164
data/tweening.lua Normal file
View File

@@ -0,0 +1,164 @@
local pi = math.pi
local sin = math.sin
local cos = math.cos
local abs = math.abs
local function backIn(t, s) s = s or 1.70158; return t * t * ((s + 1) * t - s) end
local function backOut(t, s) s = s or 1.70158; t = t - 1; return 1 + t * t * ((s + 1) * t + s) end
local function backInOut(t, s)
s = s or 1.70158
if t < 0.5 then
local tt = 2 * t
return (tt * tt * ((s * 1.525 + 1) * tt - s * 1.525)) / 2
else
local tt = 2 * t - 2
return (2 + tt * tt * ((s * 1.525 + 1) * tt + s * 1.525)) / 2
end
end
-- Bounce (helper)
local function bounceOut(t)
local n1 = 7.5625
local d1 = 2.75
if t < 1 / d1 then
return n1 * t * t
elseif t < 2 / d1 then
t = t - 1.5 / d1
return n1 * t * t + 0.75
elseif t < 2.5 / d1 then
t = t - 2.25 / d1
return n1 * t * t + 0.9375
else
t = t - 2.625 / d1
return n1 * t * t + 0.984375
end
end
easing = {
linear = function(t) return t end,
-- 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,
-- 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,
-- 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,
-- 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,
-- Back (overshoot)
easeInBack = function(t) return backIn(t) end,
easeOutBack = function(t) return backOut(t) end,
easeInOutBack = function(t) return backInOut(t) 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,
-- 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,
}
tweening = {
list = {},
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,
update = function(dt)
if #tweening.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
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
}