trigger={} 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=_action, doors=_doors, update=trigger.update, draw=trigger.draw, 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() -- start_scene(self.scene) -- remove_actor(self) --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) end function triggers:escena_abad_corfes() start_scene(scenes.abad_corfes) remove_actor(self) end function triggers:escena_abad_portes() local wx1,wy1 = coords.room_to_world(abad.hab,2,4) local wx2,wy2 = coords.room_to_world(abad.hab,6,3) if abad.escena_portes==nil and ( (abad.hab==31 and arc_get_tile(wx1,wy1)~=256) or (abad.hab==71 and arc_get_tile(wx2,wy2)~=256) ) then start_scene(scenes.abad_portes) end abad.escena_portes=true remove_actor(self) end function triggers:escena_abad_porta_casa() local wx1,wy1 = coords.room_to_world(abad.hab,6,4) if arc_get_tile(wx1,wy1)~=256 then start_scene(scenes.abad_porta_casa) end remove_actor(self) end function triggers:escena_abad_porta_batman() local wx1,wy1 = coords.room_to_world(abad.hab,5,4) if arc_get_tile(wx1,wy1)~=256 then start_scene(scenes.abad_porta_batman) end remove_actor(self) end function triggers:escena_habitacio_batman() if abad.objects.clau_premiere~=nil and abad.objects.clau_elalien~=nil then switches.start(0,0) abad.objects.clau_premiere=nil abad.objects.clau_elalien=nil remove_actor(self) else if batman.habitacio_porta_intro==nil then start_scene(scenes.habitacio_batman) batman.habitacio_porta_intro=true end end end function triggers:escena_lluita_imp() stage1_boss() start_scene(scenes.lluita_imp) remove_actor(self) end -- function triggers:teleport_a() -- abad.teleport=true -- sound.play(audio_hit) -- surf.cls(14) -- imp.reset() -- abad.hab=67 -- abad.x=24 -- end -- -- function triggers:teleport_b() -- if abad.teleport then -- sound.play(audio_hit) -- surf.cls(14) -- imp.reset() -- abad.hab=14 -- abad.x=16 -- end -- end -- -- function triggers:teleport_c() -- abad.teleport2=true -- sound.play(audio_hit) -- surf.cls(14) -- imp.reset() -- abad.hab=61 -- abad.x=24 -- end -- -- function triggers:teleport_d() -- if abad.teleport2 then -- sound.play(audio_hit) -- surf.cls(14) -- imp.reset() -- abad.hab=29 -- abad.x=24 -- end -- end