Estructura DX i escena logo JAILGAMES animada
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user