[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:
143
data/flow.lua
143
data/flow.lua
@@ -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={
|
||||
level=1,
|
||||
step={0},
|
||||
paths={ {flow_safe} },
|
||||
registre={ }
|
||||
-- sub_path_enable = false,
|
||||
-- sub_step = 0,
|
||||
-- sub_path={}
|
||||
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
|
||||
actiu = "", -- nom del registre actiu
|
||||
stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
|
||||
safe_show = false
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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")
|
||||
function flow:registrar(nom, _path)
|
||||
self.registre[nom]= {ptr=0, path=_path}
|
||||
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
|
||||
|
||||
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()
|
||||
local level_step = self.step[self.level]
|
||||
local level_path = self.paths[self.level]
|
||||
-- print("LEVEL= "..self.level)
|
||||
-- print("LEVEL_STEP= "..level_step)
|
||||
if level_step+1 > #level_path then
|
||||
-- Si s'ha acabat la llista pujar de nivell
|
||||
if self.level>1 then self.level=self.level-1 end
|
||||
level_step = self.step[self.level]
|
||||
-- level_path = self.paths[self.level]
|
||||
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:finish()
|
||||
else
|
||||
self.registre[self.actiu].ptr = ptr+1
|
||||
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||
end
|
||||
|
||||
-- següent pas
|
||||
level_step = level_step+1
|
||||
game_update = self.paths[self.level][level_step]
|
||||
|
||||
-- result = self.step[self.level]
|
||||
self.step[self.level] = level_step
|
||||
return self.actiu, self.registre[self.actiu].ptr
|
||||
end
|
||||
|
||||
function flow:restore()
|
||||
local level_step = self.step[self.level]
|
||||
game_update = self.paths[self.level][level_step]
|
||||
function flow:finish()
|
||||
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
|
||||
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||
end
|
||||
|
||||
function flow:call(nom)
|
||||
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
|
||||
flow:registrar("flow",{flow.safe})
|
||||
|
||||
@@ -379,3 +379,4 @@ function collision(a, b)
|
||||
and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
|
||||
end
|
||||
|
||||
flow:registrar("game", {game_init})
|
||||
|
||||
@@ -41,7 +41,7 @@ print("INTRO_INIT")
|
||||
surf.cls(16)
|
||||
fade.fadein()
|
||||
font.current(font_sf)
|
||||
flow:add_path({intro_intro, intro_update})
|
||||
-- flow:add_path({intro_intro, intro_update})
|
||||
flow:next()
|
||||
end
|
||||
|
||||
@@ -118,7 +118,6 @@ function intro_update()
|
||||
|
||||
-- STEP 8
|
||||
elseif intro_step==8 then
|
||||
music.play(audio_main_song)
|
||||
-- game_init(true)
|
||||
-- game_update = menu_init
|
||||
intro_end()
|
||||
@@ -130,5 +129,7 @@ end
|
||||
function intro_end()
|
||||
print("intro_end")
|
||||
fade.fadeoutin()
|
||||
flow:next()
|
||||
flow:executar("title")
|
||||
end
|
||||
|
||||
flow:registrar("intro", {intro_init, intro_intro, intro_update})
|
||||
@@ -3,11 +3,11 @@ local logo_step_wait=0
|
||||
local logo_anim={}
|
||||
local step1_finished = false
|
||||
local brillo_y = 10
|
||||
local logo_wait = 400
|
||||
local logo_wait = 500
|
||||
local logo_sf = 99
|
||||
local font_sf = 99
|
||||
local logo_sf_w = 63
|
||||
local logo_sf_h = 30
|
||||
local logo_sf_h = 20
|
||||
|
||||
function logo_anim_init ()
|
||||
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
|
||||
draw.text("JAILGAMES",0,0,15)
|
||||
draw.text("presenta",0,10,14)
|
||||
draw.text("JAILGAMES",0,20,2)
|
||||
-- draw.text("JAILGAMES",0,20,2)
|
||||
-- Restaurar font
|
||||
font.current(font_default)
|
||||
-- Inicialitzar animació
|
||||
logo_anim_init()
|
||||
flow:add_path({logo_animate, logo_end})
|
||||
-- flow:add_path({logo_animate, logo_end})
|
||||
|
||||
-- print("LOGO_ANIMATE= ")
|
||||
-- print(logo_animate)
|
||||
@@ -49,7 +49,8 @@ function logo_init()
|
||||
|
||||
-- Següent bucle
|
||||
-- game_update = logo_intro
|
||||
flow:next()
|
||||
local modul, pas=flow:next()
|
||||
print("LOGO_INIT= "..modul..", "..pas)
|
||||
end
|
||||
|
||||
function logo_draw()
|
||||
@@ -88,8 +89,10 @@ function logo_draw()
|
||||
draw.surf(0,10,55,10, 100,102,55,10); -- presenta
|
||||
|
||||
-- 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);
|
||||
pal.subpal(15)
|
||||
-- end
|
||||
end
|
||||
|
||||
@@ -170,7 +173,7 @@ function logo_end()
|
||||
-- print("LOGO_END")
|
||||
-- game_update = intro_init
|
||||
print("logo_end")
|
||||
flow:next()
|
||||
flow:executar("intro")
|
||||
-- surf.free(logo_sf)
|
||||
end
|
||||
|
||||
@@ -179,14 +182,13 @@ function logo_animate()
|
||||
logo_wait=logo_wait-1
|
||||
|
||||
-- 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
|
||||
flow:next()
|
||||
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
|
||||
local modul, pas=flow:next()
|
||||
print("LOGO_ANIMATE 1= "..modul..", "..pas)
|
||||
end
|
||||
|
||||
logo_draw()
|
||||
logo_update()
|
||||
end
|
||||
|
||||
if logo_step==7 then
|
||||
flow:next()
|
||||
end
|
||||
end
|
||||
flow:registrar("logo",{logo_init, logo_animate, logo_end})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
arcade_config = require("arcade_config")
|
||||
coords = require "coords"
|
||||
require "helpers"
|
||||
require "flow"
|
||||
|
||||
require "map"
|
||||
require "mapa"
|
||||
@@ -20,7 +21,6 @@ require "opcions"
|
||||
--require "switches"
|
||||
--require "trigger"
|
||||
|
||||
require "flow"
|
||||
|
||||
coords.set_config({
|
||||
tiles_width = arcade_config.tiles_width,
|
||||
@@ -104,15 +104,8 @@ function mini.init()
|
||||
logo_config(font_sf)
|
||||
surf.target(0)
|
||||
surf.cls(16)
|
||||
flow:add("logo", logo_init)
|
||||
flow:add("intro", intro_init)
|
||||
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()
|
||||
|
||||
flow:executar("logo")
|
||||
end
|
||||
|
||||
function mini.update()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local menu_sel = 0
|
||||
|
||||
function opcions_init()
|
||||
flow:add_path({opcions_show, opcions_end})
|
||||
-- flow:add_path({opcions_show, opcions_end})
|
||||
flow:next()
|
||||
end
|
||||
|
||||
@@ -31,9 +31,7 @@ function opcions_update()
|
||||
menu_count=0
|
||||
menu_state=update_redefine_pad_menu
|
||||
else
|
||||
-- menu_count=0
|
||||
-- menu_sel=0
|
||||
-- menu_state=update_main_menu
|
||||
-- Tornar
|
||||
flow:next()
|
||||
end
|
||||
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
|
||||
if menu_sel==-1 then menu_sel=4 end
|
||||
elseif key.press(key.ESCAPE) or pad.press(btnPause) then
|
||||
-- menu_count=0
|
||||
-- menu_sel=0
|
||||
-- menu_state=update_main_menu
|
||||
-- Tornar desde qualsevol lloc
|
||||
flow:next()
|
||||
end
|
||||
end
|
||||
@@ -57,5 +53,8 @@ end
|
||||
|
||||
function opcions_end()
|
||||
print("opcions_end")
|
||||
flow:restore()
|
||||
-- flow:restore()
|
||||
flow:finish()
|
||||
end
|
||||
|
||||
flow:registrar("opcions",{opcions_init, opcions_show, opcions_end})
|
||||
|
||||
@@ -164,9 +164,8 @@ function start_scene(scene,offset)
|
||||
if offset then scenes.offset=offset end
|
||||
-- old_update=game_update
|
||||
-- game_update=update_scene
|
||||
-- flow:add("save", game_update)
|
||||
flow:add("scene",update_scene)
|
||||
flow:call("scene")
|
||||
|
||||
flow:executar("scene", true); -- guardar l'estat anterior i executar
|
||||
end
|
||||
|
||||
function playtext(snd)
|
||||
@@ -284,7 +283,8 @@ function update_scene()
|
||||
-- fade.fadeoutin()
|
||||
-- else
|
||||
-- game_update=old_update
|
||||
flow:restore()
|
||||
-- flow:restore()
|
||||
flow:next()
|
||||
-- end
|
||||
else
|
||||
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 scenes.current_scene[scenes.dnum].die then
|
||||
-- game_init(true)
|
||||
flow:next()
|
||||
-- flow:next()
|
||||
-- game_update = menu_init
|
||||
flow:executar("title")
|
||||
else
|
||||
pause()
|
||||
end
|
||||
@@ -322,7 +323,7 @@ function update_scene()
|
||||
-- fade.fadeoutin()
|
||||
-- else
|
||||
-- game_update=old_update
|
||||
flow:restore()
|
||||
flow:next()
|
||||
-- end
|
||||
else
|
||||
scenes.dnum=scenes.dnum+1
|
||||
@@ -333,3 +334,9 @@ function update_scene()
|
||||
scenes.step=8
|
||||
end
|
||||
end
|
||||
|
||||
function end_scene()
|
||||
flow:finish()
|
||||
end
|
||||
|
||||
flow:registrar("scene",{update_scene})
|
||||
@@ -32,7 +32,7 @@ local rect_wait = 0
|
||||
function title_init()
|
||||
title_sf=surf.load("title_tiles.gif")
|
||||
surf.source(title_sf)
|
||||
flow:add_path({title_show, title_end})
|
||||
music.play(audio_main_song)
|
||||
flow:next()
|
||||
end
|
||||
|
||||
@@ -158,10 +158,12 @@ end
|
||||
function to_game()
|
||||
print("to game")
|
||||
fade.fadeoutin()
|
||||
flow:next()
|
||||
flow:executar("game")
|
||||
end
|
||||
|
||||
function to_options()
|
||||
print("to options")
|
||||
flow:call("opcions")
|
||||
flow:executar("opcions", true)
|
||||
end
|
||||
|
||||
flow:registrar("title", {title_init, title_show, title_end})
|
||||
|
||||
Reference in New Issue
Block a user