[NEW] Estructura de triggers ampliada per a soportar switchs
[NEW] Switchs convertits a triggers
This commit is contained in:
@@ -1,33 +1,57 @@
|
||||
trigger={}
|
||||
|
||||
function trigger.new(_hab,_x,_y,_fun,_escena)
|
||||
function trigger.new(_hab,_x,_y,_action,_escena,_id,_type,_doors)
|
||||
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
|
||||
_type = _type or "invisible"
|
||||
|
||||
return {
|
||||
name="trigger",
|
||||
type=_type,
|
||||
id=_id,
|
||||
escena=_escena,
|
||||
hab=_hab,
|
||||
x=world_x,
|
||||
y=world_y,
|
||||
w=16,
|
||||
h=16,
|
||||
fun=_fun,
|
||||
fun=_action,
|
||||
doors=_doors,
|
||||
update=trigger.update,
|
||||
draw=trigger.draw,
|
||||
bb={x=0,y=0,w=16,h=16} }
|
||||
end
|
||||
|
||||
function trigger:draw()
|
||||
-- do nothing
|
||||
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
||||
draw.rect(scr_x,scr_y,self.w,self.h,3)
|
||||
enabled=true,
|
||||
bb=_bb }
|
||||
end
|
||||
|
||||
function trigger:update()
|
||||
|
||||
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
|
||||
end
|
||||
self:fun()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function trigger:draw()
|
||||
local scr_x, scr_y = viewp:screen_coords( self.x, self.y )
|
||||
if self.type=="switch" then
|
||||
if self.enabled then
|
||||
draw.surf(240,128,16,16,scr_x,scr_y,16,16)
|
||||
else
|
||||
-- flipar i desactivar en gris
|
||||
pal.subpal(2,1)
|
||||
draw.surf(240,128,16,16,scr_x,scr_y,16,16,true)
|
||||
pal.subpal(2)
|
||||
end
|
||||
end
|
||||
|
||||
-- debug rect
|
||||
draw.rect(scr_x,scr_y,self.bb.w,self.bb.h,3)
|
||||
end
|
||||
|
||||
--function trigger:do_touched()
|
||||
@@ -36,6 +60,15 @@ end
|
||||
--end
|
||||
|
||||
triggers={}
|
||||
|
||||
function triggers:open_door()
|
||||
local hab= self.doors[1]-1
|
||||
for i=2,#self.doors do
|
||||
local tile_idx= self.doors[i]+1
|
||||
arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile)
|
||||
end
|
||||
end
|
||||
|
||||
function triggers:escena_abad_inici()
|
||||
start_scene(scenes.abad_inici)
|
||||
remove_actor(self)
|
||||
|
||||
Reference in New Issue
Block a user