0K=DXtAME9wt;UɥKrnWHRxuѱ{X]@yDJ F2TvͫgE#2Tv2Tv`f``ffnnnn`f``ffnf`f``fnnnfnnn`f`f```f`ffnfnnnff`f```ffffnnnff`f``ff`````f``ff`f`f``f```f````f`f```f`ff`f```ff`````ffnnfnnnnfff````fffnnnfff```f`f`ffnfnnnffff```ffffnnnnfff`````ff``f````fff````fff```fff```f`f`ff`f```fff̬̬̬̈̬̬̬̬̈̬̬ff`ff``n`ff`ffnffnnffnn`ffnfnnfff`ffnf`wvgfv`f`fwfvwvwwfwwwwgvfgvwwfwg`wggwf`f`ff`vwvww`vvg`wvvgfgw`f```ffff```ff̬̬̬̪쬪̬̬̬̪쬪fnfnfnfnffffnnnnffffffffnnnnfffffnfnfnfn`fvvvv`vgvfvvgvgwwwgwwwggwvggwvggwfg`v`wf`vwvw`w`w`w`w`wwfvwwgvwvgvfwwf`ww``vwvwfgfffffvwwwgwwwfwwwvwwwv`ffgvwwfwwwgwfwgwgvgwwvgwvvgf```ffff````ffff`ff`ff`n``ffffffnnffnnf`ffnfnfnff`ff`w`w`w`w`fw`fgw`wvg`wfffwgwvwgwvwgwvggwvggwvggwvggwwggfvwfvgvwfvfvgvwgwffwg`gfgvgvf`vffwvgfffgffgf`gg`gwff`v`fgfwgfvfwvvfwfvgfggvfffvfwwffffffffffffffffffffffffffffffff`f`fdD`ffD`Ff4D@4f@f@DD343D3C@@`D`D@DDD@@D@@@`DDDD`D@@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff434D3C4@4C3D33DC@DDD4C3DD@@@@@@@@@@@@DDDDDDDDDDDDDDDDDDDDDDDD P  )*%&'()*%&)*%&9:56789:569:56%&)*%&)*569:569:%&)*%&)*%&)*569:569:569:TUTUTUdededecPQPQc`a`abb @ABCDFGHIJKLNO@@@@@@@@@@@@@@@@012345789;<=>?0000000000000000,` ` `` ` ` ```` ` `` ``````` `` ` `` ``@``` ```@      ` ```@@@` ` ` `   ` ` `` `  ` ` ` ` `` `@` ` `` ` ` ```@@``` ``aaaaaa a aa a a aaaaAAAAAA aaaa aa aa a a aaaa a aaaaaaAAAAaa a aaaaaa a a a aaaa   `` ` `   ` ``` ` `` `h     `` ` V'``bbbbbbbbbbbbbbbbbb,` `` ,` ,`,` ,``` ,` ,`,```    ,@ @@,@,@,@,@ @ @@ @@@ @ @ @ @@@ @ @ @ @ @ @@@ @ @ @ @ @ @@@ @ @ @ @ @ @ @ @@ @@bbbbbbbbbbbbbbbbbb,` `` ,` ,`,` ,``` ,` ,`,`````` @ @ @ @@@ @ @ @ @ @ @@@ @ @@@@@@@@@ @ @ @@@ @@ @ @ @bbbbbbbbbbbbbbbb,` `` ,` ,`,` ,``` ,` ,`,````` `` ``,`` ` ` ` `` ` ` ```` ` `` ` ` `` ```@@@ @,`` ` ` `` ```@@` `` ` ` ` `` ` ` ```` `T'T'T'T'T'^'a a $'$' $' a A AAAaAa a aa aaAAa a aaaaa A AAA A A A a aa aa a a a a  a  a  a aa a  a aaAaAaAaAaaa a  a  a  a aa a  a AaAa a  a  a  a  a  a  `   @@@@@  fE DHPH[ ` ` p p[ ` ` p p | |$ pb p! |c |[ ` `<G?ff`ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`ffffffffffffffffffffffffffffnf`ffDDDDDfffDDDff`hhhhhhhhhhhhhhhhhhhhhhhhhhnn`fDDDDDffDDDfn`hfffffffffffffffffffffffffff`nfDDDDDfnfDDDf`ffhhhhhhhhhhhhhhhhhhhhhhhhhhff`ffDDDDDfffDDDff`ff `ff`ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffh nnnnfffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfhfff`fff`fffff`ffhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf``l```ffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfhf``f`f`f`f faf``fafhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf````f``f `a`d`affffh`hhh`a`D`ahnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf`hhh `a`D`affDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfh`fhfh ff`DffhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf`fhhf`ff`D`ffffffh`hffnffFDdffhnnnfh``afDdDf`affDDDDDDDDff`fDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfhff`h`fa`DDDdD`fahnDDDDDDDD`wwfvwg@DDDDDDDDnDDDDDDDDD@DDDDDDDDDDDDDnf`hl`aFDDDdFd`affvgvwwfwf`fhh``a`DDDDDfDahnfvwwwwfnffnfff`h`nff`DDDDDDDffffDDDDDDD`gvfgDDDDDDDDfDDDDDDD`vwg@DDDDDDDDDDDDfh`hffllf`fffDDDDDf`ffhnvwwnvwwfnf`ffffff`fffffff`fffffwg`f`vvggfhhn`wgfn`wvvwnffff`fffff`fffff`ffff`vg`vf`wwff`fh``````hnvfv`wfnvwwgffgnf```````ff`ff`vgvg`vwfvwvgfvwwffh`fff`fffffFfhnfwwwgvwnvfwwfffvwwwgnf`fff`fffnFdffvwwwg`wff`wwwwwgwfwgfh`fff`fffffFdhnvgwvg`wn``vwwwwfwgvgnf`fff`fff`nFdffvgwvg`w`fvwwwwvwwvg`fh`fff`ffffnfFdhnvgwfg`wfnfgwwwvwvvgfnffff`fffff`ff`n`DDff@`wfwgwvw`f@`gfgffwvvf`fhfffff`fffffffff`fffffnf`FDFdhn@@`wvwgwfvgfdf@n@@fggf`gwfvfdf@nf`fffffffffff`ffffffffffffnfFDDDFdff@`wvwgwvwfDf@Df@vgg`ggfgDf@Dfhfffffff`fffffffffffff`ffffffff`DDDDfDhn@`wvggwvf`ffD3n@vfwfgvf`ffD3nf`fffffffffffffff`fffffffffffffff`FDDDDdFdff@@`fwvggwvgD`Ff43f@@`vff`vffD`Ff43fh`fffffffffffffff`fffffffffffffff`nFDDDDDDdhn@fgwvggwvw4D@4D3Cn@fw`fgvf4D@4D3Cnffffffff`fffffffffffff`fffffffnf`FDDDDdff``wvgvgdwgw4344Cf`vgftgw4344Cfhfffff`fffffffff`fffffff`ffffhnf`wffwgddfwD3C43DnfffftdwD3C43Dnfff`@@4C3Df`@@4C3Dfhfff`fffff`fffff`ffhnfdf@@@D33nfdf@@@D33nf``````ffDf@D@DCfDf@D@DCfhf``f```fhff``ffhfhn`ffD3@@Dn`ffD3@@Dnf````f`f`h`````hffD`Ff43@@DfD`Ff43@@Dfh`an`f`h`a`hhn4D@4D3C@Dn4D@4D3C@Dnf`aan`f`h`aa`hff4344Cf4344Cfh`fn`fff`fffhnD3C43DnD3C43Dnf`fn`f`ff`f`ffff@4C3Df@4C3Dfh`a`fffff`affhnD33nD33nfa`nfffff`ha`hffDCfDCfhffn`fffff`fhff`fhhn@D@@n@D@@nf``ffffffff`h``hffD@@@@fD@@@@fhann`fffffffhahhnD@@nD@@nfffn`fffffffffffffffffh`a`nfffffff`ff`a`ffh`fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`f`fffffffff`ff`f`fff`ffDDDfffffhh`fDDDfffnffff`fffff`fffff`fff`nfDDDfnffh``````h`ffDDDfffffff``f`f`f``fhf`ff`f`ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffh````f``f`f`hffFfhnnnf`nFDdDDFDd`f`hhFdffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfh`nnFDDDFDFd`f`hffFdhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf`fFDDDDdfd`fff`hFdffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfh`fFDDDDdFd`f`fffhfFdhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnf`nfDDDDDDffffff`h`DDffffhn`DDDDDDfffff`hfhf`FDFdhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnfff`FDDDDd`fffff`fhfhfFDDDFdffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDDDDDDDDDDDDDDDDDfh`FDDDDdfffffff`hff`DDDDfDhnDDDDDDDDDDDDDDDDDDDDDDDDnDDDDDDDDDDDDDDDDDDDDDDDDnfn`DDDD`fffffffh`FDDDDdFdffffhff`FDDd`fffffffff`hFDDDDDDdhnnnf`nfDDffffffff`fffhf`FDDDDdffDDDDDDDDDDDDDDDDDDDDDDDDfDDDDDDDDff`fDDDDDDDDDfh`ffffffff`fffff`ffffhnDDDDDDDDD@DDDDDDDDDDDDDnDDDDDDDD`wwfvwg@DDDDDDDDnfff`fvgvwwfwfhfff`fffff`fffff`ffhnffnfvwwwwfnf``````ffDDDDDDD`vwg@DDDDDDDDDDDDfDDDDDDD`gvfgDDDDDDDDfh``````f`f```f`fhnvwwfnvwwnf`aFf`nf``f`df``fff`vvggffwg`fh`Fd`aa`Dhhhn`wvvwn`wgfnf`Fd`a`Dhff`wwff`f`vg`vfh`Fd`afa`Dhfhhnvwwgffgnvfv`wfnf`FdffnffaaffFDdffhhffvwvgfvwwff`vgvg`vwfha`DD`nff`FDDDDDdffhnvfwwfffvwwwgnfwwwgvwnffaf`FDFd`f``DDDDDfD`fff`wwwwwgwfwgfvwwwg`wfh`aFDDDFdnn`aFDDDDdd`hhn``vwwwwfwgvgnvgwvg`wnfaa`DDDDfD`a`DDDDDhffvwwwwvwwvg`fvgwvg`w`fh`fFDDDDdFdn`FDDDd`hnfgwwwvwvvgfnvgwfg`wfnf`FDDDDDDd``a`DDD`hff@`gfgffwvvf`f@`wfwgwvw`fhff`FDDDDdnffFDDDdffhn@@fggf`gwfvfdf@n@@`wvwgwfvgfdf@nffffff`ffff`fffffff`fffffffff@vgg`ggfgDf@Df@`wvwgwvwfDf@Dfhhn@vfwfgvf`ffD3n@`wvggwvf`ffD3nffff`fffff`fffff`ffff@@`vff`vffD`Ff43f@@`fwvggwvgD`Ff43fh``````hn@fw`fgvf4D@4D3Cn@fgwvggwvw4D@4D3Cnf````fffhff``f`ff`vgftgw4344Cf``wvgvgdwgw4344Cfh`nfff`h````fhnfffftdwD3C43Dnf`wffwgddfwD3C43Dnf`na`h`DDFDdDDhff`@@4C3Df`@@4C3Dfh`nff`h`DDDdDdDhhnfdf@@@D33nfdf@@@D33nf`n`aff`DDDDDfFhffDf@D@DCfDf@D@DCfhffnffnfaf`ff`DDDDDfDhhn`ffD3@@Dn`ffD3@@Dnf`n``aff`FDDDDDd`ffD`Ff43@@DfD`Ff43@@Dfh`f`nfaf`hFDDDDDd`hhn4D@4D3C@Dn4D@4D3C@Dnfnnnfaf`fhfDDDDDfhff4344Cf4344Cfh``fff`h`DDDDD`fhnD3C43DnD3C43Dnfnnn`hFDDDdhhff@4C3Df@4C3Dfh`n`afffDDDfhhnD33nD33`nfn`nfaf`ff`FDd`hffDCfDCffh`fffff`fffffff`ff`f`ffffhn@D@@n@D@f`nfffD@@@@fD@@`@fhfff`fffff`fffff`ffhnD@@nD@fnf``````ffffh```f`f``faf```h`fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`hf``f`a`a`hff`ffDDDDDDDDDDDD@DDDDDDDDDDDffh`nn``a`ah`fDDDDDDDDDDDD@DDDDDDDDDDDfnf`n``a`af`nfDDDDDDDDDDDD@DDDDDDDDDDDfh`nfn`ff`ah`ffDDDDDDDDDDDD@DDDDDDDDDDDfffffhffnn``ffffhffaf`ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffh`hffaff`h`hnnf`f`faf`a`f`afffhhh`n`a`fahhahnPPPPUUUPnf`naa`a``fffUUUPUPPPPUPUfhh``fahaahnUPPPUPPPPPUnf``n`ff`affPPUUPPPPUfhhffff`ffh`ahnUPUUPUUUPnf`ffffffffffff`ff`fffff`fffffffhhnnffff`ff`ff`ff`ff`ffffffffffffffffffffffffffffhf`ffffffffffffffffffffffffffffnf`hhhhhhhhhhhhhhhhhhhhhhhhhhhh`nnnnnnnnnnnnnnnnnnnnnnnnnnnn`fffffffffffffffffffffffffffh`fffffffffffffffffffffffffffn`ffhhhhhhhhhhhhhhhhhhhhhhhhhhff`ffnnnnnnnnnnnnnnnnnnnnnnnnnnffff`ffff`ffQ-- title: Juggleflask -- author: verysoftwares -- desc: A match-3 RPG -- script: lua -- saveid: POTION -- combos increase attack damage -- long chains increase next turn's swaps -- leaving Attack/Spell/Item unselected increases swaps -- matching from a hanging potion -- matching both color and shape at once t=0 potions={ } local bg=0 local glass=6 function randomchoice(tbl) return tbl[math.random(1,#tbl)] end local pot_c={1,4,8,14} function spawn_potion(px,py) local liquid=randomchoice(pot_c) while liquid==glass or liquid==bg do liquid=math.random(2,15) end local flask=math.random(1-1,4-1) flask=1+flask*2 --table.insert(potions,{liquid=liquid,flask=flask,x=px,y=py,fill=16,k=posstr(px,py)}) local out={liquid=liquid,flask=flask,x=px,y=py,fill=16,k=posstr(px,py)} return out end poke(0x7FC3F,1,1) -- hide mouse cursor mox,moy=0,0 sens=0.3 tt=0; ht=0 sel=1; tsel=1 focus='select' function game() if f_cor and t%6==0 then if not coroutine.resume(f_cor) then f_cor=nil end end --[[if focus=='select' then if btnp(2) then sel=sel-1 end if btnp(3) then sel=sel+1 end sel=((sel-1)%3)+1 end]] --[[if focus=='target' then if btnp(2) then tsel=tsel-1 end if btnp(3) then tsel=tsel+1 end tsel=((tsel-1)%#enemies)+1 end]] cls(bg) if cur_turn==plr then leftclick=left mdx,mdy,left,_,right=mouse() if right then swap=nil end mox=mox+mdx*sens; moy=moy+mdy*sens if mox<0 then mox=0 end; if mox>=240-1 then mox=240-1 end if moy<0 then moy=0 end; if moy>=136-1 then moy=136-1 end else if tmox then mox=mox+(tmox-mox)*0.2 end if tmoy then moy=moy+(tmoy-moy)*0.2 end end for i,e in ipairs(enemies) do battle_scr((i-1)%2,(i-1)//2,e.sp,i) end if not (cur_turn==plr) and focus=='attack' and not f_cor then if t-ht==90+10 then swx,swy=math.random(0,6-1),math.random(0,7-1) tmox,tmoy=8+swx*17+4,8+swy*17+4 end if t-ht==90+40 then mox,moy=tmox,tmoy swap=posstr(swx,swy) local kx,ky repeat kx,ky=swx+math.random(-1,1),swy+math.random(-1,1) until math.abs(kx-swx)+math.abs(ky-swy)==1 and not (kx<0) and not (kx>6-1) and not (ky<0) and not (ky>7-1) tmox,tmoy=8+kx*17+4,8+ky*17+4 end if t-ht==90+90 then mox,moy=tmox,tmoy tmox,tmoy=nil,nil left=true; leftclick=false end end --print(eturn) clip(0,0,math.min((2*6+2)*8,(t*0.2)*8),math.min((2*7+2)*8,(t*0.2)*8)) for k,p in pairs(potions) do if p.tx then p.x=p.x+(p.tx-p.x)*0.2 end if p.ty then p.y=p.y+(p.ty-p.y)*0.2 end pal(14,p.liquid) if p.flash and (t-p.flash)%20<10 then pal(14,6) end if swap==k then rect(p.x,p.y,16,16,2) end if focus=='attack' and not f_cor and AABB(mox,moy,1,1,p.x,p.y,16,16) then rect(p.x,p.y,16,16,1) if swap and left and not leftclick then local sx,sy=strpos(swap) local px,py=strpos(k) if math.abs(px-sx)+math.abs(py-sy)==1 then local hold=potions[k] local hx,hy=potions[k].x,potions[k].y local hx2,hy2=potions[swap].x,potions[swap].y potions[k]=potions[swap] potions[swap]=hold potions[swap].tx,potions[swap].ty=hx2,hy2 potions[k].tx,potions[k].ty=hx,hy --trace('swapped.') finish(k,swap) swap=nil leftclick=true end end if not swap and left and not leftclick then swap=k --trace('swapping...') leftclick=true end end spr(p.flask,p.x,p.y,0,1,0,0,2,2) --clip(p.x,p.y+(16-p.fill),16,p.fill) --spr(p.flask,p.x,p.y,0,1,0,0,2,2) --clip() pal() end borders(0,0,math.min(2*6+2,t*0.2),math.min(2*7+2,t*0.2)) clip((12+2+1)*8,14*8,math.min(14*8,t*0.2*8),math.min(2*8,t*0.2*8)) --[[local c1,c2,c3='','','' if sel==1 then c1='>' end if sel==2 then c2='>' end if sel==3 then c3='>' end print(string.format('%sAttack %sSpell %sItem',c1,c2,c3),15*8+8+2,14*8+8+1,5,false,1,true) if focus=='target' and btnp(4) then focus='attack'; ht=t+1 end if focus=='select' and btnp(4) and sel==1 then focus='target'; ht=t+1 end ]] btl_choice=btl_choice or {'Attack','Spell','Item'} for i,c in ipairs(btl_choice) do if focus=='select' and AABB(15*8+8+2+(i-1)*42-1,14*8+8+1-1,print(c,0,-6,0,false,1,true)+1,6+1,mox,moy,1,1) then rect(15*8+8+2+(i-1)*42-1,14*8+8+1-1,print(c,0,-6,0,false,1,true)+1,6+1,5) print(c,15*8+8+2+(i-1)*42,14*8+8+1,0,false,1,true) if i>1 then line(15*8+8+2+(i-1)*42-1,14*8+8+1+2,15*8+8+2+(i-1)*42-1+print(c,0,-6,0,false,1,true),14*8+8+1+2,14) end if left and not leftclick then if i==1 then focus='target' shout('Attack whom?') else shout('Not yet implemented.') end end else print(c,15*8+8+2+(i-1)*42,14*8+8+1,5,false,1,true) end end borders(12+2+1,14,math.min(14,t*0.2),math.min(2,t*0.2),nil,nil,true) clip() --battle_scr(0,0,40) --battle_scr(1,0,43) --battle_scr(0,1,43) --battle_scr(1,1,40) --borders(16,5,5,3,8,true) --print('Attack\nSpell\nDefend',16*8+6+6,5*8+8,5,false,1,true) if mult_sign then spr(272,mult_sign.x,mult_sign.y+8,0) spr(257+mult_sign.mult-2,mult_sign.x+8,mult_sign.y,0,1,0,0,1,2) mult_sign.y=mult_sign.y-0.5 if t-mult_sign.t>90 then mult_sign=nil end end if t-ht<90 and ((cur_turn==plr and (not (focus=='attack') or (focus=='attack' and not (intro==nil))) and (not (focus=='target') or (focus=='target' and not (intro==nil)))) or (not (cur_turn==plr) and focus=='attack')) then rect(0,136-8,240,8,6) if intro==nil then intro='Your turn.' if not (cur_turn==plr) then intro=string.format('Enemy %d\'s turn.',eturn) end end local tw=print(intro,0,-6) print(intro,240/2-tw/2,136-7,4) end if t-ht==90 then intro=nil end local msp=289 --if left then msp=290 end spr(msp,mox,moy,0,1,0,0,1,2) t=t+1 end local hc=8 function borders(bx,by,bw,bh,bc,bl,plrhp) hc=8 if t-ht<90 then hc=hc+t*0.2%3 end if bc then pal(14,bc) end if bl then rect(bx*8+2,by*8+2,bw*8,bh*8+2,0) end clip(bx*8,by*8,(bw+1)*8-1,(bh+1)*8-1) if focus=='attack' and bx==0 then pal(14,hc) end if focus=='select' and by>8 then pal(14,hc) end for bi=bx+1,bx+bw do spr(38,bi*8,by*8,0) end if focus=='select' and by<=6 then pal() end if focus=='select' and by>6 then pal(14,hc) end for bi=bx+1,bx+bw do spr(70,bi*8,by*8+bh*8,0) end if focus=='select' and by>6 then pal() end if focus=='select' and by>8 then pal(14,hc) end for bi=by+1,by+bh do spr(53,bx*8,bi*8,0) end for bi=by+1,by+bh do spr(55,bx*8+bw*8,bi*8,0) end if focus=='select' and by>8 then pal() end if focus=='select' and by>8 then pal(14,hc) end spr(37,bx*8,by*8,0) if focus=='select' and by>6 then pal(14,hc) end spr(69,bx*8,by*8+bh*8,0) spr(71,bx*8+bw*8,by*8+bh*8,0) pal() if plrhp then rect(bx*8+8-1,by*8+1+1,(bw-1)*8+2,4,0) local slice=(13*8-2)/plr.maxhp slice=math.floor(slice+0.5) for i,h in ipairs(plr.hp) do if not plr.hurt or (plr.hurt and ((#plr.hp-i>=math.abs(plr.hurt) or (#plr.hp-i0 then hurtmsg='+'..hurtmsg end print(hurtmsg,bx*8+8-1+(i-1)*slice+2-1,by*8+1+1-7,0,false,1,true) print(hurtmsg,bx*8+8-1+(i-1)*slice+2+1,by*8+1+1-7,0,false,1,true) print(hurtmsg,bx*8+8-1+(i-1)*slice+2,by*8+1+1-7-1,0,false,1,true) print(hurtmsg,bx*8+8-1+(i-1)*slice+2,by*8+1+1-7+1,0,false,1,true) print(hurtmsg,bx*8+8-1+(i-1)*slice+2,by*8+1+1-7,plr.hurt_c,false,1,true) end end clip() end if focus=='select' and by>8 then pal(14,hc) end spr(39,bx*8+bw*8,by*8,0) pal() if plrhp then rectb(bx*8+8-1,by*8+1,(bw-1)*8+2,6,6) end end enemies={ {sp=40}, {sp=43}, {sp=43}, {sp=40}, } plr={ maxhp=8, hp={}, } for i=1,plr.maxhp do table.insert(plr.hp,randomchoice(pot_c)) end for i,e in ipairs(enemies) do e.hp={} local maxhp=4 if e.sp==43 then maxhp=6 end e.maxhp=maxhp for j=1,maxhp do table.insert(e.hp,randomchoice(pot_c)) end end function battle_scr(bsx,bsy,bsp,bsi) local scrx,scry=15*8+bsx*7*8,0+bsy*7*8 borders(scrx//8,scry//8,math.min(2*3+1,t*0.2),math.min(2*3+1,t*0.2)) clip(scrx,scry,math.min((2*3+1)*8+1,(t*0.2)*8),math.min((2*3+1)*8,(t*0.2)*8)) map(0,17,6,3,scrx+8,scry+8) if focus=='target' then tsel=nil end if focus=='target' and not enemies[bsi].dod and AABB(scrx,scry,(2*3+1)*8+1,(2*3+1)*8,mox,moy,1,1) then tsel=bsi if left and not leftclick then focus='attack'; shout('Make your match.') end end if not enemies[bsi].dod and (not (focus=='target') or (focus=='target' and not (tsel==bsi) or (tsel==bsi and t%24<12))) then pal(7,0); pal(6,0) local offy=6 spr(bsp,scrx+2*8+4+1,offy+16-4+scry,0,1,0,0,3,3) spr(bsp,scrx+2*8+4-1,offy+16-4+scry,0,1,0,0,3,3) spr(bsp,scrx+2*8+4,offy+16-4+scry+1,0,1,0,0,3,3) spr(bsp,scrx+2*8+4,offy+16-4+scry-1,0,1,0,0,3,3) pal() spr(bsp,scrx+2*8+4,offy+16-4+scry,0,1,0,0,3,3) end map(0,17+3,6,6-3,scrx+8,scry+8+3*8,0) local hp=enemies[bsi].hp local maxhp=enemies[bsi].maxhp rect(scrx+8-1+1,scry+6+1+1-5-1,6*8+2-2,4-2+2,0) for i,h in ipairs(hp) do if not enemies[bsi].hurt or (enemies[bsi].hurt and ((#hp-i>=math.abs(enemies[bsi].hurt) or (#hp-i0 then hurtmsg='+'..hurtmsg end print(hurtmsg,scrx+(i-1)*(6*8/maxhp)+8+1+1,scry+6+1+1-5-1+6,0,false,1,true) print(hurtmsg,scrx+(i-1)*(6*8/maxhp)+8+1-1,scry+6+1+1-5-1+6,0,false,1,true) print(hurtmsg,scrx+(i-1)*(6*8/maxhp)+8+1,scry+6+1+1-5-1+6+1,0,false,1,true) print(hurtmsg,scrx+(i-1)*(6*8/maxhp)+8+1,scry+6+1+1-5-1+6-1,0,false,1,true) print(hurtmsg,scrx+(i-1)*(6*8/maxhp)+8+1,scry+6+1+1-5-1+6,enemies[bsi].hurt_c,false,1,true) end end rectb(scrx+8-1,scry+6+1-5-1,6*8+2,4+2,6) --if enemies[bsi].hurt_t and t-enemies[bsi].hurt_t>=60-1 then -- for i=1,enemies[bsi].hurt do if #hp>0 then table.remove(hp,#hp); if #hp==0 then enemies[bsi].dod=t+1 end end end -- enemies[bsi].hurt=nil; enemies[bsi].hurt_t=nil --end clip() end function shout(msg) intro=msg; ht=t+1 end -- palette swapping by BORB function pal(c0,c1) if(c0==nil and c1==nil) then for i=0,15 do poke4(0x3FF0*2+i,i) end else poke4(0x3FF0*2+c0,c1) end end function strpos(pos) local delim=string.find(pos,':') local x=string.sub(pos,1,delim-1) local y=string.sub(pos,delim+1) --important tonumber calls --Lua will handle a string+number addition until it doesn't return tonumber(x),tonumber(y) end function posstr(x,y) return string.format('%d:%d',x,y) end -- find by value. can return nil if not found -- wish Lua had a C-optimized implementation, kinda silly that you have to provide your own. function find(tbl,what) for i,v in ipairs(tbl) do if v==what then return i end end end function find2(tbl,k,what) for i,v in ipairs(tbl) do if v[k]==what then return i end end end -- basic AABB collision. function AABB(x1,y1,w1,h1, x2,y2,w2,h2) return (x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2) end function match3(k,test) local jx,jy=strpos(k) local j=potions[k] local i=1 local horiz={k} while potions[posstr(jx+i,jy)] and potions[posstr(jx+i,jy)].liquid==j.liquid do table.insert(horiz,posstr(jx+i,jy)) i=i+1 end i=-1 while potions[posstr(jx+i,jy)] and potions[posstr(jx+i,jy)].liquid==j.liquid do table.insert(horiz,posstr(jx+i,jy)) i=i-1 end local vert={k} i=1 while potions[posstr(jx,jy+i)] and potions[posstr(jx,jy+i)].liquid==j.liquid do table.insert(vert,posstr(jx,jy+i)) i=i+1 end i=-1 while potions[posstr(jx,jy+i)] and potions[posstr(jx,jy+i)].liquid==j.liquid do table.insert(vert,posstr(jx,jy+i)) i=i-1 end i=1 local horiz2={k} while potions[posstr(jx+i,jy)] and potions[posstr(jx+i,jy)].flask==j.flask do table.insert(horiz2,posstr(jx+i,jy)) i=i+1 end i=-1 while potions[posstr(jx+i,jy)] and potions[posstr(jx+i,jy)].flask==j.flask do table.insert(horiz2,posstr(jx+i,jy)) i=i-1 end local vert2={k} i=1 while potions[posstr(jx,jy+i)] and potions[posstr(jx,jy+i)].flask==j.flask do table.insert(vert2,posstr(jx,jy+i)) i=i+1 end i=-1 while potions[posstr(jx,jy+i)] and potions[posstr(jx,jy+i)].flask==j.flask do table.insert(vert2,posstr(jx,jy+i)) i=i-1 end local out={} if #horiz>=3 then for i,h in ipairs(horiz) do if not find(out,h) then table.insert(out,h) end end end if #vert>=3 then for i,v in ipairs(vert) do if not find(out,v) then table.insert(out,v) end end end if #horiz2>=3 then for i,h in ipairs(horiz2) do if not find(out,h) then table.insert(out,h) end end end if #vert2>=3 then for i,v in ipairs(vert2) do if not find(out,v) then table.insert(out,v) end end end --if not test and #horiz>=3 and #vert>=3 then combo() end if #out>0 then --if not test then score=score+#out*10 end --if not test then damage({horiz,horiz2,vert,vert2}) end out_dmg={horiz,horiz2,vert,vert2} return out end return false end function get_color(h,m) local out=potions[m[1]].liquid --if (not (potions[m[2]].liquid==out)) or (not (potions[m[3]].liquid==out)) then --return 7 --end for i,p in ipairs(m) do if not (potions[p].liquid==out) then return 6 end end return out end function damage(matched) local mult=0 local mux,muy for i,m in ipairs(matched) do if #m>=3 then mult=mult+1 mux,muy=strpos(m[1]) end end if mult>1 then mult_sign={x=8+mux*17,y=8+muy*17,mult=mult,t=t+1} end local tgt=enemies[tsel] if not (cur_turn==plr) then tgt=plr end for i,m in ipairs(matched) do if #m>=3 then local h=tgt.hp[#tgt.hp] local color=get_color(h,m) if not (h==color) then tgt.hurt=1 tgt.hurt_t=t+1 tgt.hurt_c=color for i=0,10-1 do coroutine.yield() end tgt.hurt=nil; tgt.hurt_t=nil; tgt.hurt_c=nil table.remove(tgt.hp,#tgt.hp) if #tgt.hp==0 then tgt.dod=true end else if #tgt.hp7-1 then break end py4=py4+1 end py4=py4-1 potions[posstr(px,py4)]=potions[posstr(px,py2)] while match3(posstr(px,py4),true) do potions[posstr(px,py4)].liquid=randomchoice(pot_c) potions[posstr(px,py4)].flask=1+math.random(1-1,4-1)*2 end potions[posstr(px,py4)]=nil while not potions[posstr(px,py3)] do if py3>7-1 then break end potions[posstr(px,py3)]=potions[posstr(px,py3-1)] potions[posstr(px,py3-1)]=nil if potions[posstr(px,py3)].ty then potions[posstr(px,py3)].y=potions[posstr(px,py3)].ty; potions[posstr(px,py3)].ty=nil end potions[posstr(px,py3)].ty=potions[posstr(px,py3)].y+17 coroutine.yield() potions[posstr(px,py3)].y=potions[posstr(px,py3)].ty; potions[posstr(px,py3)].ty=nil py3=py3+1 end py3=py3-1 local m4=match3(posstr(px,py3)) flash(m4) if m4 then goto retry end end end end end coroutine.yield() if cur_turn==plr then while enemies[eturn] and enemies[eturn].dod do eturn=eturn+1 end cur_turn=enemies[eturn] if not cur_turn then cur_turn=plr; eturn=1; focus='select'; ht=t+1 else focus='attack'; ht=t+1 end else repeat eturn=eturn+1 cur_turn=enemies[eturn] until (cur_turn and not cur_turn.dod) or not cur_turn if not cur_turn then cur_turn=plr; eturn=1; focus='select'; ht=t+1 else focus='attack'; ht=t+1 end end if plr.dod then TIC=gameover; music(); focus=nil end local ealive=false for i,e in ipairs(enemies) do if not e.dod then ealive=true; break end end if not ealive then TIC=gamewon; music(); focus=nil end end) end t2=0 local disc_msg='Welcome!\n\nThis is a very early build of the game,\ncontaining a single test encounter.\n\nYou only need mouse controls to play.' function disclaimer() idea(t2,disc_msg,'Click here to start.',function() TIC=game; focus='select'; music(6); pmem(0,1) end) t2=t2+1 end t3=0 local go_msg='Well...\n\nIt looks like you ran out of health.\n\nThat\'s a game over.' function gameover() idea(t3,go_msg,'Click here to reset.',function() reset() end) t3=t3+1 end t4=0 local gw_msg='Congratulations!\n\nYou\'ve defeated all enemies.\n\nStay tuned for the next update!' function gamewon() idea(t4,gw_msg,'Click here to reset.',function() reset() end) t4=t4+1 end function idea(tx,msg,click_msg,click_cb) cls(0) borders(6,0,math.min(2*6+2+4,tx*0.2),math.min(2*2+2,tx*0.2)) clip(6*8+8,0,math.min((2*6+2+4)*8-8,(tx*0.2)*8-8),math.min((2*2+2)*8,(tx*0.2)*8)) print(msg,8+8*6,8,6,false,1,true) clip() borders(6,14,math.min(2*6+2+4,tx*0.2),math.min(2*1,tx*0.2)) clip(6*8+8,14*8+8,math.min((2*6+2+4)*8-8,(tx*0.2)*8-8),math.min((2*1)*8,(tx*0.2)*8)) local tw=print(click_msg,0,-6,0,false,1,true) if AABB(mox,moy,1,1,240/2-tw/2-1+1,14*8+9-1,tw+1,6+1) then rect(240/2-tw/2-1+1,14*8+9-1,tw+1,6+1,6) print(click_msg,240/2-tw/2+1,14*8+9,0,false,1,true) if left and not leftclick then click_cb() end else print(click_msg,240/2-tw/2+1,14*8+9,6,false,1,true) end clip() leftclick=left mdx,mdy,left,_,right=mouse() mox=mox+mdx*sens; moy=moy+mdy*sens if mox<0 then mox=0 end; if mox>=240-1 then mox=240-1 end if moy<0 then moy=0 end; if moy>=136-1 then moy=136-1 end spr(289,mox,moy,0,1,0,0,1,2) end cur_turn=plr eturn=1 --music(6) --TIC=game if pmem(0)==0 then TIC=disclaimer; focus=nil else TIC=game; focus='select'; music(6) end