From 679e22f7fd233177046b115dd1785b7d803e3ac2 Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sun, 5 Apr 2026 13:28:01 +0200 Subject: [PATCH] [NEW] Estructura de triggers ampliada per a soportar switchs [NEW] Switchs convertits a triggers --- data/abad.lua | 25 +++++++++++---------- data/game.lua | 4 ++-- data/main.lua | 2 +- data/stage1.lua | 31 ++++++++++++++++++++------ data/switches.lua | 57 ----------------------------------------------- data/trigger.lua | 51 ++++++++++++++++++++++++++++++++++-------- 6 files changed, 82 insertions(+), 88 deletions(-) delete mode 100644 data/switches.lua diff --git a/data/abad.lua b/data/abad.lua index 881eba7..b7c846f 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -200,7 +200,7 @@ function abad_jump() local tile1_hit_type= arc_check_tile(x1_check, y_check ) local tile2_hit_type= arc_check_tile(x2_check, y_check) local not_block_tile = tile1_hit_type ~= tiletype.block and tile2_hit_type ~= tiletype.block - local switch_tile = tile1_hit_type == tiletype.switch or tile2_hit_type == tiletype.switch + --local switch_tile = tile1_hit_type == tiletype.switch or tile2_hit_type == tiletype.switch -- print("JUMP > "..x1_check..", "..x2_check..", "..y_check) -- print("T1= "..tile1_hit_type.." / T2= "..tile2_hit_type) -- local msg = "BLOCK TILE HITTED" @@ -208,17 +208,18 @@ function abad_jump() -- print(msg) -- Fer l'acció que correspon if not_block_tile then - if switch_tile then - local xx= x2_check - local yy= y_check - -- Executar el switch - if tile1_hit_type == tiletype.switch then - xx= x1_check - end - switches.start(xx, yy) - else - abad.y=abad.y-vspace - end + --if switch_tile then + -- local xx= x2_check + -- local yy= y_check + -- -- Executar el switch + -- if tile1_hit_type == tiletype.switch then + -- xx= x1_check + -- end + -- switches.start(xx, yy) + --else + -- abad.y=abad.y-vspace + --end + abad.y=abad.y-vspace else local tile1_hit = arc_get_tile(x1_check, y_check ) local tile2_hit = arc_get_tile(x2_check, y_check) diff --git a/data/game.lua b/data/game.lua index a934656..fa21cb8 100644 --- a/data/game.lua +++ b/data/game.lua @@ -12,7 +12,7 @@ require "invisible" require "caco" require "zombie" require "score" -require "switches" +-- require "switches" require "trigger" require "imp" @@ -173,7 +173,7 @@ function world_update() -- Actualizar el que queda cacau.update() - switches.update() + -- switches.update() warp.update_all() end diff --git a/data/main.lua b/data/main.lua index a6dd8a6..857af47 100644 --- a/data/main.lua +++ b/data/main.lua @@ -87,7 +87,7 @@ function mini.init() surf.target(0) surf.cls(16) - flow:executar("intro") + flow:executar("game") end function mini.update() diff --git a/data/stage1.lua b/data/stage1.lua index e246d1e..5fa403a 100644 --- a/data/stage1.lua +++ b/data/stage1.lua @@ -83,6 +83,16 @@ function stages.stage1_init() table.insert( actors, trigger.new(19,32,32,triggers.escena_habitacio_batman,"habitacio batman")) -- table.insert( actors, trigger.new(55,1,3,triggers.escena_lluita_imp,"lluita imp")) + + table.insert( actors, trigger.new(10,8,1,triggers.open_door,"","primera porta","switch",{11, 57,45}) ) + table.insert( actors, trigger.new(34,1,1,triggers.open_door,"","dos portes casa abad","switch",{32, 50,38,26,53,41,29}) ) + table.insert( actors, trigger.new(52,1,1,triggers.open_door,"","porta casa abad","switch",{72, 42,30}) ) + table.insert( actors, trigger.new(60,1,1,triggers.open_door,"","altillo","switch",{54, 54,42}) ) + table.insert( actors, trigger.new(75,6,1,triggers.open_door,"","pasillo inf","switch",{77, 50,38,26}) ) + table.insert( actors, trigger.new(75,9,1,triggers.open_door,"","acces inf casa batman","switch",{57, 53,41}) ) + table.insert( actors, trigger.new(79,5,1,triggers.open_door,"","sotan casa batman","switch",{36, 56,44}) ) + table.insert( actors, trigger.new(38,2,2,triggers.open_door,"","","switch",{39, 62,63}) ) + -- table.insert(actors,trigger.new(14,40,32,triggers.teleport_a)) -- table.insert(actors,trigger.new(67,8,32,triggers.teleport_b)) -- table.insert(actors,trigger.new(29,40,32,triggers.teleport_c)) @@ -212,7 +222,8 @@ stage1_mapa={ -- 11 { 256,66,26,27,28,29,28,29,26,27,28,29, - 256,256,256,24,256,256,256,256,15,25,256,256, + -- 256,256,256,24,256,256,256,256,15,25,256,256, + 256,256,256,24,256,256,256,256,23,25,256,256, -- 24,24,24,24,24,24,24,24,15,25,24,24, 64,68,256,256,256,256,256,256,256,25,256,256, 256,256,66,24,256,121,256,256,256,38,256,256, @@ -462,7 +473,8 @@ stage1_mapa={ -- 35 { 26,27,28,29,28,29,28,29,8,9,26,27, - 24,15,256,256,256,256,256,256,8,9,256,24, + -- 24,15,256,256,256,256,256,256,8,9,256,24, + 24,23,256,256,256,256,256,256,8,9,256,24, 24,256,256,256,256,256,256,256,8,9,256,24, 24,256,256,256,256,256,256,256,8,9,256,24, 24,256,256,256,256,256,256,256,8,9,256,24, @@ -505,7 +517,8 @@ stage1_mapa={ { 28,29,25,25,28,29,25,25,28,29,25,25, 256,256,25,25,256,256,256,256,256,256,106,24, - 256,256,15,256,256,256,256,256,256,256,95,24, + -- 256,256,15,256,256,256,256,256,256,256,95,24, + 256,256,23,256,256,256,256,256,256,256,95,24, 256,256,256,256,78,97,107,108,256,106,105,24, 256,256,256,256,94,101,102,110,103,105,98,24, 28,29,28,29,28,29,28,29,28,29,28,29, @@ -651,7 +664,8 @@ stage1_mapa={ -- 53 { 18,19,10,11,18,19,17,17,20,21,20,21, - 16,15,10,11,256,256,256,256,256,256,256,256, + -- 16,15,10,11,256,256,256,256,256,256,256,256, + 16,23,10,11,256,256,256,256,256,256,256,256, 16,256,10,11,256,256,75,76,256,256,256,256, 16,256,10,11,256,256,91,92,256,256,256,256, 16,256,10,11,256,256,18,19,256,256,256,256, @@ -733,7 +747,8 @@ stage1_mapa={ -- 61 { 18,19,21,20,21,20,21,20,21,17,18,19, - 16,15,256,256,256,256,256,256,256,77,18,19, + -- 16,15,256,256,256,256,256,256,256,77,18,19, + 16,23,256,256,256,256,256,256,256,77,18,19, 16,256,256,256,256,256,256,256,256,93,18,19, 16,256,256,256,256,256,256,116,256,78,18,19, 16,256,10,11,256,256,101,102,256,94,18,19, @@ -887,7 +902,8 @@ stage1_mapa={ -- 76 { 26,27,26,27,26,27,26,27,18,19,20,21, - 256,256,256,256,256,256,15,25,17,15,256,256, + -- 256,256,256,256,256,256,15,25,17,15,256,256, + 256,256,256,256,256,256,23,25,17,23,256,256, 256,256,256,256,256,256,256,25,17,256,256,256, 256,256,256,114,256,256,78,25,17,256,256,256, 256,256,256,256,256,95,94,25,17,256,256,256, @@ -928,7 +944,8 @@ stage1_mapa={ -- 80 { 42,43,42,43,42,43,42,43,256,256,256,256, - 256,256,256,256,256,15,42,43,256,256,256,256, + -- 256,256,256,256,256,15,42,43,256,256,256,256, + 256,256,256,256,256,23,42,43,256,256,256,256, 256,256,256,256,256,256,42,43,256,126,127,256, 256,256,256,256,256,256,42,43,256,256,256,256, 256,256,256,256,256,256,42,43,256,256,256,256, diff --git a/data/switches.lua b/data/switches.lua deleted file mode 100644 index ed3e3b3..0000000 --- a/data/switches.lua +++ /dev/null @@ -1,57 +0,0 @@ -switches={ - cooldown=0, - wait=0, - current_list=nil, - current_index=-1, - [1]={[0]={20, 53,41}}, - [11]={[21]={11, 57,45}}, - [35]={[14]={32, 50,38,26,53,41,29}}, - [53]={[14]={72, 42,30}}, - [61]={[14]={54, 54,42}}, - [76]={[19]={77, 50,38,26}, - [22]={57, 53,41}}, - [80]={[18]={36, 56,44}}, - [39]={[27]={39, 62,63}} -} ---switches[11]={[21]={11, 57,45}} ---switches[11][21]={11, 57,45} - -function switches.start(x, y) - if switches.cooldown>0 then return end - local hab, hx, hy = coords.world_to_tile(x, y) - local tile_idx = (hx+hy*mapa_room_cols)+1 - -- mapa_set_tile_by_index(hab,tile_idx,57) - arc_set_tile(x, y, editor_to_map_tile(57)) - switches.current_list=switches[hab+1][tile_idx] - switches.current_index=2 - switches.wait=0 - switches.cooldown=60 - sound.play(audio_switch) -end - -function switches.update() - if switches.cooldown>0 then switches.cooldown=switches.cooldown-1 end - if switches.current_list==nil then return end - --cls(4) - - switches.wait=switches.wait+1 - - if switches.wait>=6 then - switches.wait=0 - local hab= switches.current_list[1]-1 - local tile_idx= switches.current_list[switches.current_index]+1 --- print(hab.." ("..tile_x..", "..tile_y..")") - - -- local tile_x, tile_y = coords.room_index_to_xy ( hab, tile_idx ) - -- local world_x, world_y = coords.room_to_world(hab, tile_x, tile_y) - -- arc_set_tile(world_x, world_y, 256) - - arc_set_tile_by_index(hab,tile_idx,mapa_empty_tile) - - -- mapa_set_tile_by_index(switches.current_list[1]-1,switches.current_list[switches.current_index]+1,256) - switches.current_index=switches.current_index+1 - if switches.current_index>#switches.current_list then - switches.current_list=nil - end - end -end diff --git a/data/trigger.lua b/data/trigger.lua index 3469f7f..b85d9b4 100644 --- a/data/trigger.lua +++ b/data/trigger.lua @@ -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)