[FIX] Sistema de navegació entre pantalles (flow)

- Optimitzat el logo. Ara necessita menys memòria aprofitant les funcions de paleta
This commit is contained in:
2026-04-03 15:29:44 +02:00
parent 2564c54b3e
commit ca0393046e
8 changed files with 147 additions and 95 deletions

View File

@@ -1,63 +1,110 @@
-- flow={
-- level=1,
-- step={0},
-- actiu="",
-- pila={},
-- paths={ {flow_safe} },
-- registre={}
-- -- sub_path_enable = false,
-- -- sub_step = 0,
-- -- sub_path={}
-- }
-- function flow:print()
-- print("> STEP= "..self.step.." / "..#self.path)
-- if self.sub_path_enable then
-- print("> SUB_PATH_ENABLE= TRUE")
-- else
-- print("> SUB_PATH_ENABLE= FALSE")
-- end
-- print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
-- print("")
-- end
flow={ flow={
level=1, registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
step={0}, actiu = "", -- nom del registre actiu
paths={ {flow_safe} }, stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
registre={ } safe_show = false
-- sub_path_enable = false,
-- sub_step = 0,
-- sub_path={}
} }
function flow_safe()
print("FLOW SAFE") function flow:safe()
if not flow.safe_show then
print("[FLOW] No hi ha res en la pila")
flow.safe_show = true
end
end end
function flow:print() function flow:registrar(nom, _path)
print("> STEP= "..self.step.." / "..#self.path) self.registre[nom]= {ptr=0, path=_path}
if self.sub_path_enable then
print("> SUB_PATH_ENABLE= TRUE")
else
print("> SUB_PATH_ENABLE= FALSE")
end end
print("> SUB_STEP= "..self.sub_step.." / "..#self.sub_path)
print("") function flow:borrar(nom)
self.registre[nom].ptr=0
self.registre[nom].path=nil
end end
function flow:executar(nom, stacking)
print("FLOW EXEC "..nom)
if stacking then
table.insert(self.stack, self.actiu)
print(" APILAT "..self.actiu.."!")
end
self.actiu=nom
self.registre[self.actiu].ptr=0
self:next()
end
-- function flow:next()
-- local ptr = self.registre[self.actiu].ptr
-- local steps = #self.registre[self.actiu].path
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
-- if ptr+1>steps then
-- self.actiu = table.remove(self.stack)
-- if self.actiu==nil then
-- -- no queda res en la pila
-- self.actiu="flow"
-- self.registre[self.actiu].ptr = 1
-- else
-- -- ultim element afegit a la pila
-- -- No se fa cap acció lo que implica que se restaura l'estat en el
-- -- que s'estava abans de l'ultima cridada
-- end
-- else
-- self.registre[self.actiu].ptr = ptr+1
-- end
--
-- game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
-- return self.actiu, self.registre[self.actiu].ptr
-- end
function flow:next() function flow:next()
local level_step = self.step[self.level] local ptr = self.registre[self.actiu].ptr
local level_path = self.paths[self.level] local steps = #self.registre[self.actiu].path
-- print("LEVEL= "..self.level) print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
-- print("LEVEL_STEP= "..level_step) if ptr+1>steps then
if level_step+1 > #level_path then self:finish()
-- Si s'ha acabat la llista pujar de nivell else
if self.level>1 then self.level=self.level-1 end self.registre[self.actiu].ptr = ptr+1
level_step = self.step[self.level] game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
-- level_path = self.paths[self.level]
end end
-- següent pas return self.actiu, self.registre[self.actiu].ptr
level_step = level_step+1
game_update = self.paths[self.level][level_step]
-- result = self.step[self.level]
self.step[self.level] = level_step
end end
function flow:restore() function flow:finish()
local level_step = self.step[self.level] self.actiu = table.remove(self.stack)
game_update = self.paths[self.level][level_step] if self.actiu==nil then
-- no queda res en la pila
self.actiu="flow"
self.registre[self.actiu].ptr = 1
else
-- ultim element afegit a la pila
-- No se fa cap acció lo que implica que se restaura l'estat en el
-- que s'estava abans de l'ultima cridada
end
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
end end
function flow:call(nom) flow:registrar("flow",{flow.safe})
game_update = self.registre[nom]
end
function flow:add_path( path )
self.level = self.level+1
self.step[self.level] = 0
self.paths[self.level] = path
end
function flow:add(name, fn)
self.registre[name] = fn
end

View File

@@ -379,3 +379,4 @@ function collision(a, b)
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
end end
flow:registrar("game", {game_init})

View File

@@ -41,7 +41,7 @@ print("INTRO_INIT")
surf.cls(16) surf.cls(16)
fade.fadein() fade.fadein()
font.current(font_sf) font.current(font_sf)
flow:add_path({intro_intro, intro_update}) -- flow:add_path({intro_intro, intro_update})
flow:next() flow:next()
end end
@@ -118,7 +118,6 @@ function intro_update()
-- STEP 8 -- STEP 8
elseif intro_step==8 then elseif intro_step==8 then
music.play(audio_main_song)
-- game_init(true) -- game_init(true)
-- game_update = menu_init -- game_update = menu_init
intro_end() intro_end()
@@ -130,5 +129,7 @@ end
function intro_end() function intro_end()
print("intro_end") print("intro_end")
fade.fadeoutin() fade.fadeoutin()
flow:next() flow:executar("title")
end end
flow:registrar("intro", {intro_init, intro_intro, intro_update})

View File

@@ -3,11 +3,11 @@ local logo_step_wait=0
local logo_anim={} local logo_anim={}
local step1_finished = false local step1_finished = false
local brillo_y = 10 local brillo_y = 10
local logo_wait = 400 local logo_wait = 500
local logo_sf = 99 local logo_sf = 99
local font_sf = 99 local font_sf = 99
local logo_sf_w = 63 local logo_sf_w = 63
local logo_sf_h = 30 local logo_sf_h = 20
function logo_anim_init () function logo_anim_init ()
logo_anim={ [1] = {x0=-126, y=80, w=126, h=4, speed= 1, accel= 0.25, x1=65, delay=0}, logo_anim={ [1] = {x0=-126, y=80, w=126, h=4, speed= 1, accel= 0.25, x1=65, delay=0},
@@ -35,12 +35,12 @@ function logo_init()
-- Logo -- Logo
draw.text("JAILGAMES",0,0,15) draw.text("JAILGAMES",0,0,15)
draw.text("presenta",0,10,14) draw.text("presenta",0,10,14)
draw.text("JAILGAMES",0,20,2) -- draw.text("JAILGAMES",0,20,2)
-- Restaurar font -- Restaurar font
font.current(font_default) font.current(font_default)
-- Inicialitzar animació -- Inicialitzar animació
logo_anim_init() logo_anim_init()
flow:add_path({logo_animate, logo_end}) -- flow:add_path({logo_animate, logo_end})
-- print("LOGO_ANIMATE= ") -- print("LOGO_ANIMATE= ")
-- print(logo_animate) -- print(logo_animate)
@@ -49,7 +49,8 @@ function logo_init()
-- Següent bucle -- Següent bucle
-- game_update = logo_intro -- game_update = logo_intro
flow:next() local modul, pas=flow:next()
print("LOGO_INIT= "..modul..", "..pas)
end end
function logo_draw() function logo_draw()
@@ -88,8 +89,10 @@ function logo_draw()
draw.surf(0,10,55,10, 100,102,55,10); -- presenta draw.surf(0,10,55,10, 100,102,55,10); -- presenta
-- if logo_step_wait>=1 then -- if logo_step_wait>=1 then
draw.surf(0,20+math.floor(brillo_y),63,1, pal.subpal(15,2)
draw.surf(0,0+math.floor(brillo_y),63,1,
logo_anim[1].x0, logo_anim[1].y+math.floor(brillo_y*2), logo_anim[1].w, 1); logo_anim[1].x0, logo_anim[1].y+math.floor(brillo_y*2), logo_anim[1].w, 1);
pal.subpal(15)
-- end -- end
end end
@@ -170,7 +173,7 @@ function logo_end()
-- print("LOGO_END") -- print("LOGO_END")
-- game_update = intro_init -- game_update = intro_init
print("logo_end") print("logo_end")
flow:next() flow:executar("intro")
-- surf.free(logo_sf) -- surf.free(logo_sf)
end end
@@ -179,14 +182,13 @@ function logo_animate()
logo_wait=logo_wait-1 logo_wait=logo_wait-1
-- Següent bucle -- Següent bucle
if logo_wait==0 or key.press(key.ESCAPE) or key.press(keyShoot) or pad.press(btnShoot) or pad.press(btnPause) then if logo_step==7 or logo_wait==0 or key.press(key.ESCAPE) or key.press(keyShoot) or pad.press(btnShoot) or pad.press(btnPause) then
flow:next() local modul, pas=flow:next()
print("LOGO_ANIMATE 1= "..modul..", "..pas)
end end
logo_draw() logo_draw()
logo_update() logo_update()
end
if logo_step==7 then flow:registrar("logo",{logo_init, logo_animate, logo_end})
flow:next()
end
end

View File

@@ -1,6 +1,7 @@
arcade_config = require("arcade_config") arcade_config = require("arcade_config")
coords = require "coords" coords = require "coords"
require "helpers" require "helpers"
require "flow"
require "map" require "map"
require "mapa" require "mapa"
@@ -20,7 +21,6 @@ require "opcions"
--require "switches" --require "switches"
--require "trigger" --require "trigger"
require "flow"
coords.set_config({ coords.set_config({
tiles_width = arcade_config.tiles_width, tiles_width = arcade_config.tiles_width,
@@ -104,15 +104,8 @@ function mini.init()
logo_config(font_sf) logo_config(font_sf)
surf.target(0) surf.target(0)
surf.cls(16) surf.cls(16)
flow:add("logo", logo_init)
flow:add("intro", intro_init) flow:executar("logo")
flow:add("title", title_init)
flow:add("game", game_init)
flow:add("opcions", opcions_init)
-- flow:add("ending", ending_init)
-- flow:add("credits", credits_init)
flow:add_path( { logo_init, intro_init, title_init, game_init } )
flow:next()
end end
function mini.update() function mini.update()

View File

@@ -1,7 +1,7 @@
local menu_sel = 0 local menu_sel = 0
function opcions_init() function opcions_init()
flow:add_path({opcions_show, opcions_end}) -- flow:add_path({opcions_show, opcions_end})
flow:next() flow:next()
end end
@@ -31,9 +31,7 @@ function opcions_update()
menu_count=0 menu_count=0
menu_state=update_redefine_pad_menu menu_state=update_redefine_pad_menu
else else
-- menu_count=0 -- Tornar
-- menu_sel=0
-- menu_state=update_main_menu
flow:next() flow:next()
end end
elseif key.press(keyDown) or key.press(key.DOWN) or pad.press(pad.DOWN) or pad.press(btnDown) then elseif key.press(keyDown) or key.press(key.DOWN) or pad.press(pad.DOWN) or pad.press(btnDown) then
@@ -43,9 +41,7 @@ function opcions_update()
menu_sel=menu_sel-1 menu_sel=menu_sel-1
if menu_sel==-1 then menu_sel=4 end if menu_sel==-1 then menu_sel=4 end
elseif key.press(key.ESCAPE) or pad.press(btnPause) then elseif key.press(key.ESCAPE) or pad.press(btnPause) then
-- menu_count=0 -- Tornar desde qualsevol lloc
-- menu_sel=0
-- menu_state=update_main_menu
flow:next() flow:next()
end end
end end
@@ -57,5 +53,8 @@ end
function opcions_end() function opcions_end()
print("opcions_end") print("opcions_end")
flow:restore() -- flow:restore()
flow:finish()
end end
flow:registrar("opcions",{opcions_init, opcions_show, opcions_end})

View File

@@ -164,9 +164,8 @@ function start_scene(scene,offset)
if offset then scenes.offset=offset end if offset then scenes.offset=offset end
-- old_update=game_update -- old_update=game_update
-- game_update=update_scene -- game_update=update_scene
-- flow:add("save", game_update)
flow:add("scene",update_scene) flow:executar("scene", true); -- guardar l'estat anterior i executar
flow:call("scene")
end end
function playtext(snd) function playtext(snd)
@@ -284,7 +283,8 @@ function update_scene()
-- fade.fadeoutin() -- fade.fadeoutin()
-- else -- else
-- game_update=old_update -- game_update=old_update
flow:restore() -- flow:restore()
flow:next()
-- end -- end
else else
scenes.dnum=scenes.dnum+1 scenes.dnum=scenes.dnum+1
@@ -305,8 +305,9 @@ function update_scene()
if (key.press(key.ESCAPE) or pad.press(btnPause)) and (scenes.current_scene~=scenes.final) then if (key.press(key.ESCAPE) or pad.press(btnPause)) and (scenes.current_scene~=scenes.final) then
if scenes.current_scene[scenes.dnum].die then if scenes.current_scene[scenes.dnum].die then
-- game_init(true) -- game_init(true)
flow:next() -- flow:next()
-- game_update = menu_init -- game_update = menu_init
flow:executar("title")
else else
pause() pause()
end end
@@ -322,7 +323,7 @@ function update_scene()
-- fade.fadeoutin() -- fade.fadeoutin()
-- else -- else
-- game_update=old_update -- game_update=old_update
flow:restore() flow:next()
-- end -- end
else else
scenes.dnum=scenes.dnum+1 scenes.dnum=scenes.dnum+1
@@ -333,3 +334,9 @@ function update_scene()
scenes.step=8 scenes.step=8
end end
end end
function end_scene()
flow:finish()
end
flow:registrar("scene",{update_scene})

View File

@@ -32,7 +32,7 @@ local rect_wait = 0
function title_init() function title_init()
title_sf=surf.load("title_tiles.gif") title_sf=surf.load("title_tiles.gif")
surf.source(title_sf) surf.source(title_sf)
flow:add_path({title_show, title_end}) music.play(audio_main_song)
flow:next() flow:next()
end end
@@ -158,10 +158,12 @@ end
function to_game() function to_game()
print("to game") print("to game")
fade.fadeoutin() fade.fadeoutin()
flow:next() flow:executar("game")
end end
function to_options() function to_options()
print("to options") print("to options")
flow:call("opcions") flow:executar("opcions", true)
end end
flow:registrar("title", {title_init, title_show, title_end})