[NEW] Mòdul Live scene per a escenes de joc
[NEW] Modificat mòdul flow per a poder afegir registres que no se van a executar inmediatament i així programar escenes encadenades
This commit is contained in:
+28
-26
@@ -25,7 +25,8 @@ flow={
|
|||||||
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
|
registre={}, -- {nom {ptr (a l'estat actual), path (llista de funcions ordenada)} ...}
|
||||||
actiu = "", -- nom del registre actiu
|
actiu = "", -- nom del registre actiu
|
||||||
stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
|
stack = {}, -- guarda els canvis de registre per a poder tornar a l'estat anterior
|
||||||
safe_show = false
|
safe_show = false,
|
||||||
|
add_stack = {}, -- pila per a pasar a stack en quan arribe el següent executar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +38,9 @@ function flow:safe()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function flow:registrar(nom, _path)
|
function flow:registrar(nom, _path)
|
||||||
|
print("[FLOW] REGISTRAR => "..nom)
|
||||||
self.registre[nom]= {ptr=0, path=_path}
|
self.registre[nom]= {ptr=0, path=_path}
|
||||||
|
print(self.registre[nom].ptr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function flow:borrar(nom)
|
function flow:borrar(nom)
|
||||||
@@ -45,41 +48,31 @@ function flow:borrar(nom)
|
|||||||
self.registre[nom].path=nil
|
self.registre[nom].path=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function flow:add(nom)
|
||||||
|
print("[FLOW] add "..nom)
|
||||||
|
self.add_stack[#self.add_stack+1] = nom
|
||||||
|
end
|
||||||
|
|
||||||
function flow:executar(nom, stacking)
|
function flow:executar(nom, stacking)
|
||||||
-- print("FLOW EXEC "..nom)
|
print("[FLOW] EXEC "..nom)
|
||||||
if stacking then
|
if stacking then
|
||||||
table.insert(self.stack, self.actiu)
|
-- table.insert(self.stack, self.actiu)
|
||||||
|
self.stack[#self.stack+1] = self.actiu
|
||||||
-- print(" APILAT "..self.actiu.."!")
|
-- print(" APILAT "..self.actiu.."!")
|
||||||
|
if #self.add_stack>0 then
|
||||||
|
for i, v in ipairs(self.add_stack) do
|
||||||
|
self.stack[#self.stack+1] = v
|
||||||
|
end
|
||||||
|
self.add_stack={}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
self.actiu=nom
|
self.actiu=nom
|
||||||
self.registre[self.actiu].ptr=0
|
self.registre[self.actiu].ptr=0
|
||||||
self:next()
|
self:next()
|
||||||
end
|
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()
|
||||||
|
print("[FLOW] NEXT "..self.actiu);
|
||||||
local ptr = self.registre[self.actiu].ptr
|
local ptr = self.registre[self.actiu].ptr
|
||||||
local steps = #self.registre[self.actiu].path
|
local steps = #self.registre[self.actiu].path
|
||||||
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
|
-- print("FLOW_NEXT= "..self.actiu..", "..ptr..", "..steps)
|
||||||
@@ -94,7 +87,9 @@ function flow:next()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function flow:finish()
|
function flow:finish()
|
||||||
|
print("[FLOW] FINISH "..self.actiu);
|
||||||
self.actiu = table.remove(self.stack)
|
self.actiu = table.remove(self.stack)
|
||||||
|
print("[FLOW] ACTIU "..self.actiu);
|
||||||
if self.actiu==nil then
|
if self.actiu==nil then
|
||||||
-- no queda res en la pila
|
-- no queda res en la pila
|
||||||
self.actiu="flow"
|
self.actiu="flow"
|
||||||
@@ -103,7 +98,14 @@ function flow:finish()
|
|||||||
-- ultim element afegit a la pila
|
-- ultim element afegit a la pila
|
||||||
-- No se fa cap acció lo que implica que se restaura l'estat en el
|
-- No se fa cap acció lo que implica que se restaura l'estat en el
|
||||||
-- que s'estava abans de l'ultima cridada
|
-- que s'estava abans de l'ultima cridada
|
||||||
|
|
||||||
|
-- Per si es un estat afegit amb add
|
||||||
|
if self.registre[self.actiu].ptr ==0 then
|
||||||
|
self.registre[self.actiu].ptr = 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
local curr_flow = self.registre[self.actiu]
|
||||||
|
local ptr = self.registre[self.actiu].ptr
|
||||||
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
game_update = self.registre[self.actiu].path[self.registre[self.actiu].ptr]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ require "batman"
|
|||||||
require "health_potion"
|
require "health_potion"
|
||||||
require "tiles_layer2"
|
require "tiles_layer2"
|
||||||
require "batvio"
|
require "batvio"
|
||||||
|
require "live_scene"
|
||||||
|
|
||||||
local DEBUG = false
|
local DEBUG = false
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
live_scene = {
|
||||||
|
--scene_update = nil,
|
||||||
|
--scene_end = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- function live_scene.scene_update()
|
||||||
|
-- -- buida
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- function live_scene.scene_end()
|
||||||
|
-- -- buida
|
||||||
|
-- end
|
||||||
|
|
||||||
|
function live_scene.update_stage1_ending()
|
||||||
|
print("UPDATING")
|
||||||
|
flow:next()
|
||||||
|
end
|
||||||
|
|
||||||
|
function live_scene.end_stage1_ending()
|
||||||
|
print("END")
|
||||||
|
flow:finish()
|
||||||
|
end
|
||||||
|
|
||||||
|
function live_scene.start( name, op )
|
||||||
|
local flow_name = "live_scene_"..name
|
||||||
|
local update_func = live_scene["update_"..name]
|
||||||
|
local end_func = live_scene["end_"..name]
|
||||||
|
--live_scene.scene_update = update_func
|
||||||
|
--live_scene.scene_end = end_func
|
||||||
|
print("LIVE SCENE START")
|
||||||
|
if op=="add" then
|
||||||
|
print("ADD")
|
||||||
|
flow:registrar(flow_name,{update_func,end_func})
|
||||||
|
flow:add(flow_name);
|
||||||
|
else
|
||||||
|
print("EXEC")
|
||||||
|
flow:executar("live_scene", true);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
flow:registrar("live_scene",{
|
||||||
|
live_scene.scene_update,
|
||||||
|
live_scene.scene_end
|
||||||
|
})
|
||||||
@@ -201,6 +201,7 @@ function start_scene(_scene, offset, stop_music)
|
|||||||
-- game_update=update_scene
|
-- game_update=update_scene
|
||||||
scene.running = true
|
scene.running = true
|
||||||
if not stop_music then scene.stop_music = false end
|
if not stop_music then scene.stop_music = false end
|
||||||
|
print("SCENE START")
|
||||||
flow:executar("scene", true); -- guardar l'estat anterior i executar
|
flow:executar("scene", true); -- guardar l'estat anterior i executar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -167,7 +167,8 @@ function stages.stage1_init()
|
|||||||
|
|
||||||
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
|
||||||
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
|
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
|
||||||
local abad_x, abad_y = coords.room_to_world ( 18, 9, 3 )
|
table.insert( actors, trigger.new(8,4,3,triggers.escena_stage1_ending,"stage1 ending","TR09") )
|
||||||
|
local abad_x, abad_y = coords.room_to_world ( 8, 9, 3 )
|
||||||
|
|
||||||
abad:move(abad_x, abad_y)
|
abad:move(abad_x, abad_y)
|
||||||
abad_make_safe( true )
|
abad_make_safe( true )
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ function triggers:escena_stage1_ending()
|
|||||||
print("STAGE 1 ENDING")
|
print("STAGE 1 ENDING")
|
||||||
abad.update = abad_nop
|
abad.update = abad_nop
|
||||||
remove_actor(self)
|
remove_actor(self)
|
||||||
|
live_scene.start("stage1_ending", "add")
|
||||||
start_scene(scenes.stage1_ending, nil, false)
|
start_scene(scenes.stage1_ending, nil, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user