[NEW] Switchs i triggers dependents enllaçats

[NEW] Visió remota al obrir-se una porta
This commit is contained in:
2026-04-05 16:17:24 +02:00
parent 679e22f7fd
commit 4c2c8dc84f
5 changed files with 104 additions and 20 deletions

View File

@@ -1,11 +1,12 @@
trigger={}
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors)
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors,_linked_id)
local world_x, world_y = coords.room_to_world(_hab,_x,_y)
_bb={x=0,y=0,w=16,h=16} --default
if _type=="switch" then _bb={x=0,y=0,w=16,h=17} end
-- if _type=="switch" then _bb={x=0,y=0,w=16,h=17} end
if _id then print("NEW => ".._id) end
_type = _type or "invisible"
if _linked_id then print("LINKED => ".._id.." -> ".._linked_id[1].." +") end
return {
name="trigger",
type=_type,
@@ -20,17 +21,21 @@ function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors)
doors=_doors,
update=trigger.update,
draw=trigger.draw,
linked_id=_linked_id,
enabled=true,
bb=_bb }
end
function trigger:update()
if not self.enabled then return end
if self.hab==abad.hab then
if collision(abad,self) then
if self.type=="switch" and self.enabled then
sound.play(audio_switch)
self.enabled=false
self.enabled=false
if self.linked_id then
disable_actor_by_id(self.linked_id)
end
end
self:fun()
end
@@ -38,6 +43,7 @@ function trigger:update()
end
function trigger:draw()
if self.type~="switch" and not self.enabled then return end
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
if self.type=="switch" then
if self.enabled then
@@ -63,6 +69,9 @@ triggers={}
function triggers:open_door()
local hab= self.doors[1]-1
if hab~=abad.hab then
remote_view(hab)
end
for i=2,#self.doors do
local tile_idx= self.doors[i]+1
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)