[NEW] Dialeg funcionant.

This commit is contained in:
2026-04-22 22:30:34 +02:00
parent a811ece34f
commit ea19c43865
4 changed files with 68 additions and 12 deletions

View File

@@ -2,7 +2,19 @@ dialeg={
list = {}, 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 ) function dialeg.new( _text, _actor )
print(_text)
table.insert( table.insert(
dialeg.list, dialeg.list,
{ {
@@ -14,10 +26,10 @@ function dialeg.new( _text, _actor )
} ) } )
end end
function dialeg:draw( ) function dialeg.draw( )
local i = 1 local i = 1
while i <= #self.list do while i <= #dialeg.list do
local d = self.list[i] local d = dialeg.list[i]
if d.time>0 and d.actor then if d.time>0 and d.actor then
if viewp:inside(d.actor.x, d.actor.y, d.actor.w, d.actor.h) 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) font.current(font_curr)
d.time = d.time-1 d.time = d.time-1
i = i + 1
end end
i = i + 1
else else
table.remove(self.list, i) table.remove(dialeg.list, i)
end end
end end
end end

View File

@@ -216,6 +216,8 @@ function world_update()
-- switches.update() -- switches.update()
warp.update_all() warp.update_all()
dialeg.update()
end end
function world_draw() function world_draw()
@@ -238,7 +240,7 @@ function world_draw()
end end
end end
dialeg:draw() dialeg.draw()
if stages.boss_loaded then stage_draw_middle() end if stages.boss_loaded then stage_draw_middle() end

View File

@@ -4,11 +4,18 @@ local shine_pos = 0
local map_backup = {} local map_backup = {}
local actors_backup = {} local actors_backup = {}
function distancia(a, b) function distancia(a, b, hv)
local dx = (a.x-b.x) local dx = (a.x-b.x)
local dy = (a.y-b.y) local dy = (a.y-b.y)
local r = math.sqrt(dx*dx+dy*dy) local r = 0
return r 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 end
function in_table(tabla, valor) function in_table(tabla, valor)

View File

@@ -69,7 +69,8 @@ function stages.stage1_init()
table.insert( actors, caco.new(74,3,2,false) ) table.insert( actors, caco.new(74,3,2,false) )
table.insert( actors, caco.new(75,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, 4, 3,true) )
table.insert( actors, zombie.new(2, 5, 3,false) ) table.insert( actors, zombie.new(2, 5, 3,false) )
table.insert( actors, zombie.new(3, 3, 3,true) ) 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(46, 3, 3,false) )
table.insert( actors, zombie.new(54, 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(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, 5, 3,false) )
table.insert( actors, zombie.new(73, 7, 3,false) ) table.insert( actors, zombie.new(73, 7, 3,false) )
table.insert( actors, zombie.new(75, 3, 3,true) ) 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(29,40,32,triggers.teleport_c))
-- table.insert(actors,trigger.new(61,8,32,triggers.teleport_d)) -- 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 ( 10, 4, 3 )
-- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 ) -- local abad_x, abad_y = coords.room_to_world ( 54, 8, 3 )
abad:move(abad_x, abad_y) abad:move(abad_x, abad_y)