0,ʁ>S}Wup8d%qy)6o;]AsVl3-pwwwwwpwwwwwpwwwwwwWUUUUwwWUUUUwwWUUUUwpwUUUfVUwpwUUUfVUwpwUUUfVUwpwUefUUUwpwUefUUUwpwUefUUUwpwfVUUuwpwfVUUuwpwfVUUuwwwwwwwwwwwww """" " """" """" " """" """" " """" " " " " " " " " " " " " "" " " " "" " " " "" " " " " " " " " " " " " " " " " """" """" " """" """" " """" """"6-- title: flo -- author: diguh -- desc: planter -- site: website link -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua local W=240 local H=136 local frameCount=0 local MONEY=0 local ZERO=27 local plntFlwr={ slct=-1, lst={} } for i=1,6 do plntFlwr.lst[i]=0 end local M={ x=0, y=0, clk=false, s=32, plt=-1, timeSince=0, flwr=-1, fHeld=0 } local PTRS={ hand=32, point=33, hold=34, bucket=35, leaf=36 } local PLT={ w=16, h=16, cnt=5, pad=2 } local plts={} local menu={ x=W-60, y=20, h=12, bs={ 1, -- save 17, -- coin 32, -- harvest 35, -- bucket 36, -- leaf } } local GRW_TIME=120 ----------------------------------------------- PLOTS function crtPlts() local strtX=W/2-((PLT.w+PLT.pad*2)*PLT.cnt)/2+4 local strtY=H/2-((PLT.h+PLT.pad*2)*PLT.cnt)/2 for i=0,PLT.cnt do plts[i]={} for j=0,PLT.cnt do plts[i][j]={ x=strtX+i*(PLT.w+PLT.pad)-PLT.w, y=strtY+j*(PLT.h+PLT.pad)-PLT.h, isDry=true, flwr=-1, wetTime=0 } end end end function drwPlts() for _,a in ipairs(plts) do for _,p in ipairs(a) do local brdr=13 if p.flwr~=-1 and p.flwr.age>=5*GRW_TIME then brdr=4 end rectb(p.x,p.y,PLT.w,PLT.h,brdr) if mouseIn(p.x,p.y,PLT.w,PLT.h) then rect(p.x,p.y,PLT.w,PLT.h,brdr) if M.s==PTRS.hand then M.s=PTRS.point end M.plt=p end drwPlt(p.isDry,p.x,p.y) if p.wetTime>0 then p.wetTime=p.wetTime-1 elseif not p.isDry then p.isDry=true end if p.flwr ~= -1 then drwFlwr(p.flwr.type,p.flwr.color,p.x+8,p.y+10,p.flwr.age) if not p.isDry then p.flwr.age=p.flwr.age+1 end end end end end function wetPlt(p) p.isDry=false p.wetTime=math.random(GRW_TIME)+GRW_TIME*1.5 end function drwPlt(isDry,x,y) local id=8 if not isDry then id=24 end spr(id,x,y+8,0) spr(id+1,x+8,y+8,0) end ----------------------------------------------- FLOWERS function drwFlwr(id,color,x,y,age) x=x-4 y=y-8 if age<5*GRW_TIME then spr(age//GRW_TIME+48,x,y,0) return end spr(52,x,y,0) pal(12,color) spr(id,x,y-5,0) pal() end function crtFlwr(plt,type,color) plt.flwr={ age=0, type=type, color=color } end function rndFlwr() return { type=math.random(64,70), color=math.random(1,15), } end ----------------------------------------------- MENU function drwMenu() local tWid=print(MONEY,W/2-2,10,0) print(MONEY,W/2-tWid/2,10,4) local sX=W/2-72 local sY=8 for i=1,6 do local f=plntFlwr.lst[i] local c=12 if plntFlwr.slct==i then c=14 end local xP=sX local yP=sY+i*12 rectb(xP,yP,11,11,c) if f~=-1 and f~=0 then pal(12,f.color) spr(f.type,xP+2,yP+1,0) pal() end if keyp(ZERO+i) then plntFlwr.slct=i end end local i=0 for n in pairs(menu.bs) do local b=menu.bs[n] local yDiff=0 if mouseIn(menu.x,menu.y+i*menu.h,8,8) then yDiff=math.sin(frameCount/10)*1.1 pal(13,12) if M.clk then if b~=17 and b~=1 then M.s=b elseif M.flwr~=-1 then MONEY=MONEY+10*M.fHeld M.fHeld=0 elseif b==1 then Save() end M.flwr=-1 end end spr(b,menu.x,menu.y+i*menu.h+yDiff,0) i=i+1 pal() end end function mouseClk() if M.plt~=-1 and M.clk then if M.s==PTRS.bucket then wetPlt(M.plt) elseif M.s==PTRS.leaf then local f=rndFlwr() if plntFlwr.slct~=-1 and plntFlwr.lst[plntFlwr.slct]~=0 then f=plntFlwr.lst[plntFlwr.slct] end crtFlwr(M.plt,f.type,f.color) elseif M.plt.flwr~=-1 and M.plt.flwr.age>=5*GRW_TIME then M.flwr={ type=M.plt.flwr.type, color=M.plt.flwr.color } M.fHeld=M.fHeld+1 M.plt.flwr=-1 end end end function holdingFlwr() local type=M.flwr.type local color=M.flwr.color local age=6*GRW_TIME for i=1,6 do if keyp(ZERO+i) then plntFlwr.lst[i]={ type=M.flwr.type, color=M.flwr.color } end end drwFlwr(type,color,M.x+3,M.y+3,age) spr(PTRS.hold,M.x,M.y,0) end function mouseIn(x,y,w,h) return M.x<=x+w and M.x>=x and M.y>=y and M.y<=y+h end crtPlts() function game() poke(0x3FFB, 1) if M.s==PTRS.point then M.s=PTRS.hand end M.plt=-1 cls(0) local x,y,clk=mouse() M.x=x M.y=y M.clk=clk if clk then M.timeSince=M.timeSince+1 else M.timeSince=0 end drwPlts() drwMenu() mouseClk() if keyp(48) then plntFlwr.slct=-1 end if M.flwr==-1 then if M.s==PTRS.leaf and plntFlwr.slct~=-1 and plntFlwr.lst[plntFlwr.slct]~=0 then local f=plntFlwr.lst[plntFlwr.slct] pal(12,f.color) spr(f.type,M.x-3,M.y,0) pal() else spr(M.s,M.x-3,M.y,0) end else holdingFlwr() end frameCount=frameCount+1 end -- swap c0 and c1 colors, call pal() to reset 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 TIC() cls(0) spr(82,70,20,0,3,0,0,4,4) --game() end function Save() pmem(0,MONEY) pmem(20,1) for i=1,6 do if plntFlwr.lst[i]~=0 then pmem(i,plntFlwr.lst[i].type) pmem(i*9,plntFlwr.lst[i].color) end end end function Load() if pmem(20)~=1 then return end MONEY=pmem(0) for i=1,6 do plntFlwr.lst[i]={ type=pmem(i), color=pmem(i*9) } end end Load()