- Afegits els "switches" i el concepte de "flags"

This commit is contained in:
2023-01-31 15:46:03 +01:00
parent f03ed38d77
commit 2fb0749cf7
4 changed files with 37 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()

18
data/switches.lua Normal file
View File

@@ -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.x+v.w and y>=v.y and y<v.y+v.h then
return v
end
end
return nil
end,
}