From cb032645687ce768cb7275ef2744be9b048c444f Mon Sep 17 00:00:00 2001 From: JailGamer Date: Sun, 22 Mar 2026 20:10:18 +0100 Subject: [PATCH] Switches funcionant --- data/abad.lua | 7 ++++++- data/game.lua | 9 +++++++-- data/main.lua | 1 + data/mapa.lua | 1 + data/switches.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 data/switches.lua diff --git a/data/abad.lua b/data/abad.lua index 5b8e417..2a96091 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -166,8 +166,13 @@ function abad_jump() -- 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 - switches.start(abad.hab,1+xx+yy*12) + if tile1_hit_type == tiletype.switch then + xx= x1_check + end + switches.start(xx, yy) else abad.y=abad.y-vspace end diff --git a/data/game.lua b/data/game.lua index 7883cd2..2925030 100644 --- a/data/game.lua +++ b/data/game.lua @@ -21,12 +21,13 @@ viewp:position(0,0) actors={} function game_init(menu) - abad_init() table.insert(actors,abad) + local abad_x, abad_y = arc_mapa_get_coords ( 10, 4, 3 ) - print(abad_x..", "..abad_y) + -- print(abad_x..", "..abad_y) abad:move(abad_x, abad_y) + local scr_ax, scr_ay = viewp:screen_coords(abad_x, abad_y) game_update=update_game @@ -88,6 +89,8 @@ function update_game() -- if vp_y+1<=(tile_h*mapa_room_rows*mapa_pisos)-(res_h) then vp_y = vp_y+1 end --end + load_tilemap( sf_mapa ) + if key.press(key.N1) then local hab = math.random(0, 79) local hab_x = math.random(0, mapa_room_cols-1) @@ -114,6 +117,8 @@ function update_game() -- end --end end + switches.update() + local vp_x = viewp.x local vp_y = viewp.y --viewp:position(vp_x, vp_y) diff --git a/data/main.lua b/data/main.lua index 72ad9af..9384ddd 100644 --- a/data/main.lua +++ b/data/main.lua @@ -1,6 +1,7 @@ require "fade" require "audio" require "intro" +require "switches" require "map" local arcade_config = require("arcade_config") diff --git a/data/mapa.lua b/data/mapa.lua index 52ec6dc..ce7fac4 100644 --- a/data/mapa.lua +++ b/data/mapa.lua @@ -124,6 +124,7 @@ function mapa_set_tile(hab,x,y,tile) end function mapa_set_tile_by_index(hab,index,tile) +print("MSTBI= R"..hab..", I"..index..", T="..mapa[1+hab][index].." -> "..tile) mapa[1+hab][index]=tile end diff --git a/data/switches.lua b/data/switches.lua new file mode 100644 index 0000000..05883f0 --- /dev/null +++ b/data/switches.lua @@ -0,0 +1,47 @@ +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 = arc_mapa_get_map_coords(x, y) + local tile_idx = (hx+hy*mapa_room_cols)+1 +print("Switch > "..x..", "..y.." / "..hab..", "..hx..", "..hy.." T="..tile_idx) + mapa_set_tile_by_index(hab,tile_idx,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 + 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