diff --git a/data/dialeg.lua b/data/dialeg.lua index fb7f818..a6fe53a 100644 --- a/data/dialeg.lua +++ b/data/dialeg.lua @@ -2,7 +2,19 @@ dialeg={ list = {}, } +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.new( _text, _actor ) +print(_text) table.insert( dialeg.list, { @@ -14,10 +26,10 @@ function dialeg.new( _text, _actor ) } ) end -function dialeg:draw( ) +function dialeg.draw( ) local i = 1 - while i <= #self.list do - local d = self.list[i] + while i <= #dialeg.list do + local d = dialeg.list[i] if d.time>0 and d.actor then if viewp:inside(d.actor.x, d.actor.y, d.actor.w, d.actor.h) then @@ -53,11 +65,10 @@ function dialeg:draw( ) font.current(font_curr) d.time = d.time-1 - - i = i + 1 end + i = i + 1 else - table.remove(self.list, i) + table.remove(dialeg.list, i) end end end diff --git a/data/game.lua b/data/game.lua index de39f40..6e0782d 100644 --- a/data/game.lua +++ b/data/game.lua @@ -216,6 +216,8 @@ function world_update() -- switches.update() warp.update_all() + + dialeg.update() end function world_draw() @@ -238,7 +240,7 @@ function world_draw() end end - dialeg:draw() + dialeg.draw() if stages.boss_loaded then stage_draw_middle() end diff --git a/data/helpers.lua b/data/helpers.lua index 2795aa2..74190b7 100644 --- a/data/helpers.lua +++ b/data/helpers.lua @@ -4,11 +4,18 @@ local shine_pos = 0 local map_backup = {} local actors_backup = {} -function distancia(a, b) +function distancia(a, b, hv) local dx = (a.x-b.x) local dy = (a.y-b.y) - local r = math.sqrt(dx*dx+dy*dy) - return r + local r = 0 + if hv==nil then + r = math.sqrt(dx*dx+dy*dy) + elseif hv=="h" then + if math.abs(dy)<=16 then r=dx else r=999999 end + elseif hv=="v" then + if math.abs(dx)<=16 then r=dy else r=999999 end + end + return math.abs(r) end function in_table(tabla, valor) diff --git a/data/stage1.lua b/data/stage1.lua index e4a93d2..9aa9188 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -69,7 +69,8 @@ function stages.stage1_init() table.insert( actors, caco.new(74,3,2,false) ) table.insert( actors, caco.new(75,3,2,false) ) - table.insert( actors, zombie.new(2, 3, 3,false) ) + local zombie1 = zombie.new(2, 3, 3,false) + table.insert( actors, zombie1 ) table.insert( actors, zombie.new(2, 4, 3,true) ) table.insert( actors, zombie.new(2, 5, 3,false) ) table.insert( actors, zombie.new(3, 3, 3,true) ) @@ -84,7 +85,8 @@ function stages.stage1_init() table.insert( actors, zombie.new(46, 3, 3,false) ) table.insert( actors, zombie.new(54, 3, 3,false) ) table.insert( actors, zombie.new(68, 3, 3,false) ) - table.insert( actors, zombie.new(73, 3, 3,false) ) + local zombie2 = zombie.new(73, 3, 3,false) + table.insert( actors, zombie2 ) table.insert( actors, zombie.new(73, 5, 3,false) ) table.insert( actors, zombie.new(73, 7, 3,false) ) table.insert( actors, zombie.new(75, 3, 3,true) ) @@ -119,6 +121,40 @@ 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" + } + ) + + 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!" + } + ) + + 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)