From 90fd942d842c20330e61576e7126ca019a8d1da7 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sun, 26 Apr 2026 19:57:53 +0200 Subject: [PATCH] [NEW] Moguts els dialegs a trigger per event --- data/dialeg.lua | 42 ++++++++++++++++++------------------- data/game.lua | 1 - data/stage1.lua | 47 ++++++++++++++---------------------------- data/trigger_event.lua | 42 +++++++++++++++++++++++++++---------- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/data/dialeg.lua b/data/dialeg.lua index a6fe53a..097d9a9 100644 --- a/data/dialeg.lua +++ b/data/dialeg.lua @@ -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 diff --git a/data/game.lua b/data/game.lua index 9fbeb34..c448288 100644 --- a/data/game.lua +++ b/data/game.lua @@ -219,7 +219,6 @@ function world_update() warp.update_all() trigger_event.update() - dialeg.update() end function world_draw() diff --git a/data/stage1.lua b/data/stage1.lua index e04d9de..b620162 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -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 ) diff --git a/data/trigger_event.lua b/data/trigger_event.lua index bb0f2e6..9e97f14 100644 --- a/data/trigger_event.lua +++ b/data/trigger_event.lua @@ -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