Estructura DX i escena logo JAILGAMES animada
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
-- Funcions de suavitzat — entrada t in [0, 1], sortida ~[0, 1].
|
||||
-- Algunes (back/bounce) poden sortir de [0,1] temporalment.
|
||||
--
|
||||
-- Referencia: https://easings.net (versions clausurades algebraicament)
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.linear(t)
|
||||
return t
|
||||
end
|
||||
|
||||
function M.inQuad(t)
|
||||
return t * t
|
||||
end
|
||||
|
||||
function M.outQuad(t)
|
||||
local u = 1 - t
|
||||
return 1 - u * u
|
||||
end
|
||||
|
||||
function M.inOutQuad(t)
|
||||
if t < 0.5 then
|
||||
return 2 * t * t
|
||||
else
|
||||
local u = 2 * (1 - t)
|
||||
return 1 - 0.5 * u * u
|
||||
end
|
||||
end
|
||||
|
||||
function M.inCubic(t)
|
||||
return t * t * t
|
||||
end
|
||||
|
||||
function M.outCubic(t)
|
||||
local u = 1 - t
|
||||
return 1 - u * u * u
|
||||
end
|
||||
|
||||
-- Botet: cau, rebota, cau, rebota mes petit, ... fins quedar-se.
|
||||
function M.outBounce(t)
|
||||
local n = 7.5625
|
||||
local d = 2.75
|
||||
if t < 1/d then
|
||||
return n * t * t
|
||||
elseif t < 2/d then
|
||||
local u = t - 1.5/d
|
||||
return n * u * u + 0.75
|
||||
elseif t < 2.5/d then
|
||||
local u = t - 2.25/d
|
||||
return n * u * u + 0.9375
|
||||
else
|
||||
local u = t - 2.625/d
|
||||
return n * u * u + 0.984375
|
||||
end
|
||||
end
|
||||
|
||||
-- Overshoot (es passa del valor i torna).
|
||||
function M.outBack(t)
|
||||
local c1 = 1.70158
|
||||
local c3 = c1 + 1
|
||||
local u = t - 1
|
||||
return 1 + c3 * u * u * u + c1 * u * u
|
||||
end
|
||||
|
||||
function M.inBack(t)
|
||||
local c1 = 1.70158
|
||||
local c3 = c1 + 1
|
||||
return c3 * t * t * t - c1 * t * t
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,63 @@
|
||||
-- Input modern — wrappers per btn/btnp amb un mapejat unic d'accions.
|
||||
--
|
||||
-- Cada accio te una llista de tecles (perque l'usuari puga jugar amb
|
||||
-- fletxes o amb O P Q A indistintament). En cada frame guardem l'estat
|
||||
-- 'held' (mante premut) i 'pressed' (acaba de ser premut). Aixi les
|
||||
-- escenes no han de saber res de KEY_*.
|
||||
|
||||
local M = {}
|
||||
|
||||
M.accions = {
|
||||
amunt = { KEY_UP, KEY_Q },
|
||||
avall = { KEY_DOWN, KEY_A },
|
||||
esq = { KEY_LEFT, KEY_O },
|
||||
dreta = { KEY_RIGHT, KEY_P },
|
||||
accept = { KEY_RETURN, KEY_SPACE, KEY_KP_ENTER },
|
||||
cancel = { KEY_ESCAPE },
|
||||
}
|
||||
|
||||
M.held = {}
|
||||
M.pressed = {}
|
||||
|
||||
local function qualsevol_btn(tecles)
|
||||
for i = 1, #tecles do
|
||||
if btn(tecles[i]) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function qualsevol_btnp(tecles)
|
||||
for i = 1, #tecles do
|
||||
if btnp(tecles[i]) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function M.reset()
|
||||
for nom, _ in pairs(M.accions) do
|
||||
M.held[nom] = false
|
||||
M.pressed[nom] = false
|
||||
end
|
||||
end
|
||||
|
||||
function M.tick()
|
||||
for nom, tecles in pairs(M.accions) do
|
||||
M.held[nom] = qualsevol_btn(tecles)
|
||||
M.pressed[nom] = qualsevol_btnp(tecles)
|
||||
end
|
||||
end
|
||||
|
||||
-- Helpers per a les escenes — mes legibles que llegir taules directament.
|
||||
function M.es_mante(accio) return M.held[accio] == true end
|
||||
function M.acaba_premuda(accio) return M.pressed[accio] == true end
|
||||
|
||||
-- Per a la pantalla titol/logo: «qualsevol tecla» per avançar.
|
||||
local TECLES_AVANCAR = { KEY_RETURN, KEY_SPACE, KEY_KP_ENTER,
|
||||
KEY_O, KEY_P, KEY_Q, KEY_A,
|
||||
KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT }
|
||||
|
||||
function M.qualsevol_tecla()
|
||||
return qualsevol_btnp(TECLES_AVANCAR)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,49 @@
|
||||
-- Maquina d'escenes (FSM simple).
|
||||
--
|
||||
-- Cada escena es una taula amb les funcions opcionals:
|
||||
-- entra(servicis, args) -- en activar-se (rep els servicis globals)
|
||||
-- ix() -- en eixir (per netejar timers, etc)
|
||||
-- update(dt) -- per frame, amb delta en segons
|
||||
-- draw() -- per frame, despres d'update()
|
||||
--
|
||||
-- El motor d'ascii no separa update i draw; ho fem aci nosaltres per
|
||||
-- mantindre el codi de cada escena ordenat.
|
||||
|
||||
local M = {}
|
||||
|
||||
M.servicis = {} -- injectat des de main.lua
|
||||
M.escenes = {} -- nom -> escena
|
||||
M.actual = nil -- escena activa
|
||||
|
||||
function M.registra(nom, escena)
|
||||
M.escenes[nom] = escena
|
||||
end
|
||||
|
||||
function M.canvia(nom, args)
|
||||
local seguent = M.escenes[nom]
|
||||
if not seguent then
|
||||
log("[manager] escena desconeguda: "..tostr(nom))
|
||||
return
|
||||
end
|
||||
if M.actual and M.actual.ix then
|
||||
M.actual.ix()
|
||||
end
|
||||
M.actual = seguent
|
||||
if M.actual.entra then
|
||||
M.actual.entra(M.servicis, args or {})
|
||||
end
|
||||
end
|
||||
|
||||
function M.update(dt)
|
||||
if M.actual and M.actual.update then
|
||||
M.actual.update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function M.draw()
|
||||
if M.actual and M.actual.draw then
|
||||
M.actual.draw()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,33 @@
|
||||
-- Delta time helper.
|
||||
--
|
||||
-- L'ascii no exposa delta directament. Calculem en cada frame el temps
|
||||
-- transcorregut amb time() (ms des d'inici). El primer frame retornem 0
|
||||
-- per evitar salts grans, i clampem dt a 1/15 s per protegir-nos de
|
||||
-- pauses (ESC -> consola) o stalls.
|
||||
|
||||
local M = {}
|
||||
|
||||
local DT_MAX = 1.0 / 15.0 -- 66 ms; un parell de frames a 30 fps
|
||||
|
||||
local last_ms = 0
|
||||
local first = true
|
||||
|
||||
function M.reset()
|
||||
last_ms = time()
|
||||
first = true
|
||||
end
|
||||
|
||||
function M.tick()
|
||||
local now = time()
|
||||
local dt = (now - last_ms) / 1000.0
|
||||
last_ms = now
|
||||
if first then
|
||||
first = false
|
||||
return 0.0
|
||||
end
|
||||
if dt > DT_MAX then dt = DT_MAX end
|
||||
if dt < 0 then dt = 0 end
|
||||
return dt
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user