From 2fb0749cf7576e9cfe26bdb5be4ff788acadd1df Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 31 Jan 2023 15:46:03 +0100 Subject: [PATCH] - Afegits els "switches" i el concepte de "flags" --- data/actors.lua | 4 ++++ data/game.ini | 2 +- data/game.lua | 16 ++++++++++++++-- data/switches.lua | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 data/switches.lua diff --git a/data/actors.lua b/data/actors.lua index ac63ea5..27d8c0b 100644 --- a/data/actors.lua +++ b/data/actors.lua @@ -73,6 +73,10 @@ actors={ v.path=nil game.update() scene.cont() + if v.name == actors.hero then + local switch = switches.search(v.x,v.y) + if switch then switch.action() end + end end end end diff --git a/data/game.ini b/data/game.ini index fe16776..586ec49 100644 --- a/data/game.ini +++ b/data/game.ini @@ -3,4 +3,4 @@ config=ja2 width=160 height=144 zoom=5 -files=scene.lua,balloon.lua,actors.lua,game.lua,mapa.lua,editor.lua,textbox.lua,menu.lua,main.lua +files=switches.lua,scene.lua,balloon.lua,actors.lua,game.lua,mapa.lua,editor.lua,textbox.lua,menu.lua,main.lua diff --git a/data/game.lua b/data/game.lua index e2969b0..4e5c97a 100644 --- a/data/game.lua +++ b/data/game.lua @@ -2,13 +2,25 @@ game={ cam={x=0,y=0}, init=function() + flags={} mapa.load("test.map") actors.add({name="usufondo",x=11,y=9,o="r",gfx={x=0,y=0}}) actors.add({name="jailer",x=6,y=9,o="r",gfx={x=32,y=0}}) + actors.hero="jailer" + update=game.update - scene.start({function() actors.search("usufondo").path={pos=0,route='rrrruro'} end, - function() balloon.show("HOLA\nQUE TAL?","usufondo",true) end }) + switches.add({x=8,y=8,w=1,h=3,action= + function() + if not flags.usu1 then + flags.usu1=true + scene.start({ + function() actors.search("usufondo").path={pos=0,route='rrrruro'} end, + function() balloon.show("HOLA\nQUE TAL?","usufondo",true) end + }) + end + end + }) end, update=function() diff --git a/data/switches.lua b/data/switches.lua new file mode 100644 index 0000000..758b139 --- /dev/null +++ b/data/switches.lua @@ -0,0 +1,18 @@ +switches={ + list={}, + + add=function(switch) + if not switch.w then switch.w=1 end + if not switch.h then switch.h=1 end + table.insert(switches.list, switch) + end, + + search=function(x,y) + for i,v in ipairs(switches.list) do + if x>=v.x and x=v.y and y