From e7db2bf49fa3d7dde9963aba21bbf89bfbee5a4b Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sun, 23 Oct 2022 14:25:44 +0200 Subject: [PATCH] switches implemented --- abad.lua | 21 ++++++++++++++++++--- game.ini | 2 +- main.lua | 14 ++++++++++++-- map.lua | 24 ++++++++++++------------ mapa.lua | 10 ++++++++-- switches.lua | 36 ++++++++++++++++++++++++++++++++++++ tiles.gif | Bin 3151 -> 3241 bytes 7 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 switches.lua diff --git a/abad.lua b/abad.lua index 828d752..43a8b3d 100644 --- a/abad.lua +++ b/abad.lua @@ -132,8 +132,8 @@ end function abad_state_jumping() abad.frame=3 abad.wait=abad.wait+1 - print(abad.x,1,50) - print(abad.y,10,50) + --print(abad.x,1,50) + --print(abad.y,10,50) if abad.wait==6 then abad.wait=0 @@ -146,7 +146,22 @@ function abad_state_jumping() if abad.y>0 then if check_tile(abad.hab,abad.x+4,abad.y-2)~=tiletype.block then if (abad.x+4)&7==0 or check_tile(abad.hab,abad.x+12,abad.y-2)~=tiletype.block then - abad.y=abad.y-2 + + if check_tile(abad.hab,abad.x+4,abad.y-2)==tiletype.switch then + -- Executar el switch + local xx=min(11,max(0,flr((abad.x+4)/8))) + local yy=min(5,max(0,flr((abad.y-2)/8))) + switches.start(abad.hab,1+xx+yy*12) + --cls(4) + elseif (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y-2)==tiletype.switch then + -- Executar el switch + local xx=min(11,max(0,flr((abad.x+12)/8))) + local yy=min(5,max(0,flr((abad.y-2)/8))) + switches.start(abad.hab,1+xx+yy*12) + --cls(4) + else + abad.y=abad.y-2 + end end end else diff --git a/game.ini b/game.ini index 76beff1..bd490b9 100644 --- a/game.ini +++ b/game.ini @@ -2,4 +2,4 @@ title=Cacaus width=128 height=96 zoom=4 -files=score.lua,map.lua,mapa.lua,cacau.lua,caco.lua,zombie.lua,abad.lua,main.lua +files=score.lua,switches.lua,map.lua,mapa.lua,cacau.lua,caco.lua,zombie.lua,abad.lua,main.lua diff --git a/main.lua b/main.lua index 6001331..02c73d7 100644 --- a/main.lua +++ b/main.lua @@ -57,7 +57,7 @@ function _update() if mode==modes.editing then draw_hab(abad.hab,0,0,true) - text(abad.hab,100,10,2) + text(abad.hab,120,1,2) sspr(0,64,128,48,0,48) color(3) @@ -84,6 +84,11 @@ function _update() end local mx,my=mousex(),mousey() + if mx>>3 < 12 and my>>3 < 6 then + text(mx>>3,100,10,2) + text(my>>3,111,10,2) + text((mx>>3)+(my>>3)*12,118,10,2) + end if mbtn(1) then if my>=48 then seltile=(mx>>3)+((my-48)>>3)*16 @@ -95,6 +100,10 @@ function _update() mapa_set_tile(abad.hab,mx>>3,my>>3,255) end end + if mx>>3 < 12 and my>>3 < 6 then + local tx,ty=(mx>>3)<<3,(my>>3)<<3 + rect(tx,ty,tx+8,ty+8,3) + end else draw_hab(abad.hab,0,0) text(abad.hab,1,1,2) @@ -114,7 +123,8 @@ function _update() end end cacau.update() - + switches.update() + if btnp(KEY_RETURN) then mode=modes.editing end diff --git a/map.lua b/map.lua index e4b801d..6d65c39 100644 --- a/map.lua +++ b/map.lua @@ -1,11 +1,11 @@ mapa={ -- 1 { - 18,19,20,21,20,21,20,21,20,21,20,21, - 16,72,255,255,255,255,255,255,255,255,255,255, - 16,88,255,255,255,255,255,255,255,255,255,255, - 16,255,255,255,255,255,255,255,255,255,255,255, - 16,255,255,255,255,255,255,255,255,255,255,255, + 18,19,20,21,20,21,20,21,18,19,20,21, + 16,72,255,255,255,15,255,255,255,17,255,255, + 16,88,255,255,255,255,255,255,255,17,255,255, + 16,255,255,255,255,255,255,255,255,38,255,255, + 16,255,255,255,255,255,255,255,255,38,255,255, 20,21,20,21,20,21,20,21,20,21,20,21, }, @@ -501,9 +501,9 @@ mapa={ }, -- 51 { - 41,45,44,45,44,45,45,255,255,255,44,45, - 40,255,255,255,255,255,255,255,255,41,255,255, - 40,255,255,255,255,255,255,255,3,255,255,255, + 42,43,44,45,44,45,45,255,255,255,44,45, + 40,72,255,255,255,255,255,255,255,41,255,255, + 40,88,255,255,255,255,255,255,3,255,255,255, 40,255,255,255,255,255,255,3,255,255,255,255, 40,255,255,255,255,255,3,255,255,255,255,255, 44,45,44,45,44,45,44,45,44,45,44,45, @@ -651,12 +651,12 @@ mapa={ }, -- 66 { - 20,21,20,21,20,21,20,21,20,21,20,21, + 48,49,48,48,50,49,48,50,49,48,48,50, 255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255, - 20,21,20,21,20,21,20,21,20,21,20,21, + 42,43,42,43,42,43,255,255,255,255,255,255, + 255,255,255,255,42,43,3,255,255,255,255,255, + 255,255,255,255,42,43,42,43,42,43,42,43, }, -- 67 diff --git a/mapa.lua b/mapa.lua index 66bacb2..a376f7e 100644 --- a/mapa.lua +++ b/mapa.lua @@ -1,5 +1,5 @@ --mapa={} -tiletype={void=0,stair=1,half=2,block=3} +tiletype={void=0,stair=1,switch=2,half=3,block=4} function mapa_new() for my=0,7 do @@ -58,6 +58,10 @@ function mapa_set_tile(hab,x,y,tile) mapa[1+hab][1+x+y*12]=tile end +function mapa_set_tile_by_index(hab,index,tile) + mapa[1+hab][index]=tile +end + function mapa_get_tile(hab,x,y) return mapa[1+hab][1+x+y*12] end @@ -83,8 +87,10 @@ function check_tile(hab,x,y) local tile=mapa_get_tile(hab,xx,yy) if tile<8 then return tiletype.half - elseif tile<16 then + elseif tile<15 then return tiletype.stair + elseif tile==15 then + return tiletype.switch elseif tile<64 then return tiletype.block else diff --git a/switches.lua b/switches.lua new file mode 100644 index 0000000..e0277fb --- /dev/null +++ b/switches.lua @@ -0,0 +1,36 @@ +switches={ + cooldown=0, + wait=0, + current_list=nil, + current_index=-1, +} +switches[1]={} +switches[1][18]={1, 57,45} + +function switches.start(hab,tile) + if switches.cooldown>0 then return end + mapa_set_tile_by_index(hab,tile,57) + switches.current_list=switches[hab+1][tile] + print(tile) + switches.current_index=2 + switches.wait=0 + switches.cooldown=60 +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,255) + 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/tiles.gif b/tiles.gif index e36cd321674e648858df94ead17a3f491f3314f5..8c8c78d1348f8b811d10d90ebfdbf4b36510708e 100644 GIT binary patch delta 1089 zcmV-H1it&v7^xYscnE)L6+`;!rw|Z8NNGyb>}l|%2PkPtRXR)npfP?nJ2%$F*#B9fDkuHe{^X9qJ#o36%GZw1om>p9MRZ z-U6-`yfqbTe2IT5->kxyzT15&aT%gPEgH7JW(}}W*$ZIo_4K}a#Vvl3OIZXT*M^@R zB7x7_!UC(;zY{j_YTpFk`68IGmc?y{?MK>-y~)BE_HTs`Sm4DC)w?5JFnvMnG@~A| zgJaBafHiC3_Yta-NM_loNE-f}Xi z;~(1e%WSMNn8)1QoKTp{X3Z^1)tuP9Di{B?N=>V76Y>BDGyni~zB5r&O23pc)z5qm zv_q5`X#A}7x_N)ttsz zxrv5!qbq;S>OCLRm4beCp%?q;_hu*O6}X zn^9WsJ6l^NweGYl^*!r#evixmuXn4(2XHbwZPtGXFLVPI&hUmi{NW5&001N|@reth z;uNL1d4%41aaR$)Hy$20usABHD%aW01MmCq68D}?*TzlpEZj{pF`B>C7Ue|TVWpRBaM zAPcFz{5fR+0H9<$?l%+3w}11O5U+6(;dfo*M}V|}f0Q8?0my)NV}SN&66GX;(84)- zp9dTUfq|*gc^e3N9*8QCw-F^cf+(1RD!76y*n%$jf-o3^GB|@YSc5irgE*LjI=F)g H6%YVBpV}n~ delta 998 zcmVl4{4K4vr$A3#nA4n$w|L zb*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