[NEW] Moguts els dialegs a trigger per event

This commit is contained in:
2026-04-26 19:57:53 +02:00
parent ca4169f2f1
commit 90fd942d84
4 changed files with 68 additions and 64 deletions

View File

@@ -2,29 +2,29 @@ dialeg={
list = {},
}
dialegs = {}
-- dialegs = {}
function dialeg.update()
for i,d in ipairs(dialegs) do
if distancia(d.actor1, d.actor2, d.direccio)<=d.distancia and d.enabled then
dialeg.new(d.text, d.actor1)
d.enabled=false
end
end
end
-- function dialeg.update()
-- for i,d in ipairs(dialegs) do
-- if distancia(d.actor1, d.actor2, d.direccio)<=d.distancia and d.enabled then
-- dialeg.new(d.text, d.actor1)
-- d.enabled=false
-- end
-- end
-- end
function dialeg.new( _text, _actor )
print(_text)
table.insert(
dialeg.list,
{
actor= _actor,
text=_text,
time = 120,
w = math.floor(4.6*#_text),
h = 20,
} )
end
-- function dialeg.new( _text, _actor )
-- print(_text)
-- table.insert(
-- dialeg.list,
-- {
-- actor= _actor,
-- text=_text,
-- time = 120,
-- w = math.floor(4.6*#_text),
-- h = 20,
-- } )
-- end
function dialeg.draw( )
local i = 1

View File

@@ -219,7 +219,6 @@ function world_update()
warp.update_all()
trigger_event.update()
dialeg.update()
end
function world_draw()

View File

@@ -121,42 +121,27 @@ function stages.stage1_init()
-- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c))
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d))
table.insert(
dialegs,
{ actor1=premiere,
actor2=abad,
distancia=150,
direccio = "h",
enabled=true,
text="Ma que cosa fare"
}
)
trigger_event.new("Premiere dialeg 1",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
premiere, abad, 150, "Ma que cosa fare", 150)
table.insert(
dialegs,
{ actor1=zombie1,
actor2=abad,
distancia=250,
direccio = "h",
enabled=true,
text="Sereeeeebrooooosssss"
}
)
table.insert(
dialegs,
{ actor1=zombie2,
actor2=abad,
distancia=250,
direccio = "h",
enabled=true,
text="Aaaaaargh... per ell!"
}
)
trigger_event.new("Zombie 1 dialeg",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
zombie1, abad, 150, "Sereeeeebrooooosssss", 250)
trigger_event.new("Zombie 2 dialeg",
trigger_ev.dialeg_trigger,
trigger_ev.dialeg_init,
nil,
zombie2, abad, 150, "Aaaaaargh... per ell!", 250)
local abad_x, abad_y = coords.room_to_world ( 10, 4, 3 )
local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
abad:move(abad_x, abad_y)
abad_make_safe( true )

View File

@@ -4,12 +4,17 @@ trigger_event = {
trigger_ev = {}
function trigger_event.new ( _name, _tr_func, _tr_init, _tr_update )
function trigger_event.new ( _name, _tr_func, _tr_init, _tr_update, _a, _b, _time, _text, _distancia )
table.insert( trigger_event.list, {
name = _name,
trigger = _tr_func,
init = _tr_init,
update = _tr_update,
actor = _a,
actor_b = _b,
time = _time,
text = _text,
distancia = _distancia,
enabled = true,
running = false,
})
@@ -81,14 +86,14 @@ function trigger_ev:premiere_healer_update()
local hab, tx, ty = coords.world_to_tile(premiere.x, premiere.y)
if hab == 55 and tx==0 and ty==3 and premiere.health_wait==100 then
-- 55 (0,3)
local _text = "Tenne! Io t'achudo. Figo!";
table.insert(
dialegs,
{ actor1=premiere,
actor2=abad,
distancia=500,
direccio = "",
enabled=true,
text="Tenne! Io t'achudo. Figo!"
dialeg.list,
{ actor=premiere,
text=_text,
time=200,
w = math.floor(4.6*#_text),
h = 20,
}
)
premiere.health_wait = premiere.health_wait - 1
@@ -101,11 +106,26 @@ function trigger_ev:premiere_healer_update()
end
end
function premiere_dialeg1_trigger ()
if h_collision( premiere, abad) and
distancia ( premiere, abad )<=150
-- DIALEG GENERAL
function trigger_ev:dialeg_trigger ()
if h_collision( self.actor, self.actor_b ) and
distancia ( self.actor, self.actor_b )<=self.distancia
then
self:init()
return true
end
return false
end
function trigger_ev:dialeg_init()
table.insert(
dialeg.list,
{ actor=self.actor,
text=self.text,
time=self.time,
w = math.floor(4.6*#self.text),
h = 20,
}
)
trigger_event.disable(self.name)
end