local love=love local gc,tm=love.graphics,love.timer local ms,kb,tc=love.mouse,love.keyboard,love.touch local fs,sys,wd=love.filesystem,love.system,love.window local int,abs,rnd,max,min=math.floor,math.abs,math.random,math.max,math.min local find,format=string.find,string.format local ins,rem=table.insert,table.remove local Timer=tm.getTime -- sort=table.sort local F=false null=function()end ------------------------------------------------------------- system=sys.getOS() local xOy=love.math.newTransform() local mx,my,mouseShow=-20,-20,false local touching--1st touching ID scr={x=0,y=0,w=gc.getWidth(),h=gc.getHeight(),k=1}local scr=scr scene="" bgmPlaying=nil curBG="none" voicePlaying={} local devMode=0 kb.setKeyRepeat(true) kb.setTextInput(false) ms.setVisible(false) ------------------------------------------------------------- local Fonts={} function setFont(s) if s~=currentFont then if Fonts[s]then gc.setFont(Fonts[s]) else local t=gc.setNewFont("font.ttf",s-5) Fonts[s]=t gc.setFont(t) end currentFont=s end return Fonts[s] end customSel={22,22,1,1,7,3,1,1,8,4,1,1,1} preField={h=20} for i=1,10 do preField[i]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}end for i=11,20 do preField[i]={0,0,0,0,0,0,0,0,0,0}end freeRow={L=40}for i=1,40 do freeRow[i]={0,0,0,0,0,0,0,0,0,0}end --Game system Vars setting={ ghost=true,center=true, grid=false,swap=true, fxs=3,bg=true, das=10,arr=2, sddas=0,sdarr=2, lang=1, sfx=true,bgm=true, vib=3,voc=false, fullscreen=false, bgblock=true, skin=1,smo=true, keyMap={ {"left","right","x","z","c","up","down","space","tab","r","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"dpleft","dpright","a","b","y","dpup","dpdown","rightshoulder","x","leftshoulder","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, {"","","","","","","","","","","","",""}, },--keyboard & joystick virtualkey={ {80,720-80,6400,80},--moveLeft {240,720-80,6400,80},--moveRight {1280-240,720-80,6400,80},--rotRight {1280-400,720-80,6400,80},--rotLeft {1280-240,720-240,6400,80},--rotFlip {1280-80,720-80,6400,80},--hardDrop {1280-80,720-240,6400,80},--softDrop {1280-80,720-400,6400,80},--hold {80,80,6400,80},--restart }, virtualkeyAlpha=3, virtualkeyIcon=true, virtualkeySwitch=false, frameMul=100, } stat={ run=0,game=0,time=0, key=0,rotate=0,hold=0,piece=0,row=0, atk=0,send=0,recv=0,pend=0, clear_1=0,clear_2=0,clear_3=0,clear_4=0, spin_0=0,spin_1=0,spin_2=0,spin_3=0, b2b=0,b3b=0,pc=0,score=0, } virtualkey={ {80,720-80,6400,80},--moveLeft {240,720-80,6400,80},--moveRight {1280-240,720-80,6400,80},--rotRight {1280-400,720-80,6400,80},--rotLeft {1280-240,720-240,6400,80},--rotFlip {1280-80,720-80,6400,80},--hardDrop {1280-80,720-240,6400,80},--softDrop {1280-80,720-400,6400,80},--hold {80,360,6400,80},--func {80,80,6400,80},--restart --[[ {x=0,y=0,r=0},--toLeft {x=0,y=0,r=0},--toRight {x=0,y=0,r=0},--toDown ]] } virtualkeyDown={F,F,F,F,F,F,F,F,F,F,F,F,F} virtualkeyPressTime={0,0,0,0,0,0,0,0,0,0,0,0,0} --User datas&settings ------------------------------------------------------------- require("class") require("toolfunc") require("ai") require("gamefunc") require("list") require("dataList") require("texture") local Tmr=require("timer") local Pnt=require("paint") --Requires ------------------------------------------------------------- local BGblockList={}for i=1,16 do BGblockList[i]={v=0}end local BGblock={tm=150,next=7,ct=0} local powerInfoCanvas,updatePowerInfo if sys.getPowerInfo()~="unknown"then powerInfoCanvas=gc.newCanvas(147,22) updatePowerInfo=function() local state,pow=sys.getPowerInfo() if state~="unknown"then gc.setCanvas(powerInfoCanvas)gc.push("transform")gc.origin() gc.clear(0,0,0,.3) gc.setLineWidth(4) setFont(25) local charging if state~="battery"then gc.setColor(1,1,1) if state=="nobattery"then gc.setLineWidth(2) gc.line(61.5,.5,83.5,22.5) elseif state=="charging"or state=="charged"then gc.draw(chargeImage,84,3) F=true end end if pow then if charging then gc.setColor(0,1,0) elseif pow>50 then gc.setColor(1,1,1) elseif pow>26 then gc.setColor(1,1,0) elseif pow<26 then gc.setColor(1,0,0) else gc.setColor(.5,0,1)--special~ end ::L:: gc.rectangle("fill",61,6,pow*.15,10) gc.setColor(1,1,1) gc.draw(batteryImage,58,3) gc.print(pow.."%",94,-3) end gc.print(os.date("%H:%M",os.time()),2,-3) gc.pop()gc.setCanvas() end end end local function getNewBlock() BGblock.ct=BGblock.ct+1 if BGblock.ct==17 then BGblock.ct=1 end local t=BGblockList[BGblock.ct] t.bn,t.size=BGblock.next,2+3*rnd() t.b=blocks[t.bn][rnd(0,3)] t.x=rnd(-#t.b[1]*t.size*30+100,1180) t.y=-#t.b*30*t.size t.v=t.size*(1+rnd()) BGblock.next=BGblock.next%7+1 return t end local sceneInit={ load=function() loading=1--Loading mode loadnum=1--Loading counter loadprogress=0--Loading bar(0~1) loadTip=text.tips[rnd(#text.tips)] end, intro=function() count=0 BGM("blank") updatePowerInfo() end, main=function() modeSel,levelSel=modeSel or 1,levelSel or 3 BGM("blank") collectgarbage() end, music=function() sel=1 BGM() end, mode=function() curBG="none" saveData() destroyPlayers() BGM("blank") end, custom=function() sel=sel or 1 destroyPlayers() curBG=customRange.bg[customSel[12]] BGM(customRange.bgm[customSel[13]]) end, draw=function() curBG="none" clearSureTime=0 pen,sx,sy=1,1,1 end, play=function() kb.setKeyRepeat(false) restartCount=0 if needResetGameData then resetGameData() needResetGameData=nil end end, pause=function() end, setting=function() curBG="none" end, setting2=function() curBoard=1 keyboardSet=1 joystickSet=1 keyboardSetting=false joystickSetting=false end,--Control settings setting3=function() curBG="game1" defaultSel=1 sel=nil snapLevel=1 end,--Touch setting help=function() curBG="none" end, stat=function() end, history=function() updateLog=require"updateLog" curBG="lightGrey" sel=2 end, quit=function() love.event.quit() end, } local function onVirtualkey(x,y) local d2,nearest,distance for K=1,#virtualkey do local b=virtualkey[K] d2=(x-b[1])^2+(y-b[2])^2 if d20 then keyDown.mode("up") elseif y<0 then keyDown.mode("down") end end function keyDown.mode(key) if key=="down"then if modeSel<#modeID then modeSel=modeSel+1 levelSel=int(#modeLevel[modeID[modeSel]]*.4)+1 SFX("move",.4) end elseif key=="up"then if modeSel>1 then modeSel=modeSel-1 levelSel=int(#modeLevel[modeID[modeSel]]*.4)+1 SFX("move",.4) end elseif key=="left"then if levelSel>1 then levelSel=levelSel-1 end elseif key=="right"then if levelSel<#modeLevel[modeID[modeSel]]then levelSel=levelSel+1 end elseif key=="return"then loadGame(modeSel,levelSel) elseif key=="c"then gotoScene("custom") elseif key=="escape"then back() end end function wheelmoved.music(x,y) if y>0 then keyDown.music("up") elseif y<0 then keyDown.music("down") end end function keyDown.music(key) if key=="down"then sel=sel%#musicID+1 elseif key=="up"then sel=(sel-2)%#musicID+1 elseif key=="return"or key=="space"then if bgmPlaying~=musicID[sel]then BGM(musicID[sel]) else BGM() end elseif key=="escape"then back() end end function keyDown.custom(key) if key=="left"then customSel[sel]=(customSel[sel]-2)%#customRange[customID[sel]]+1 if sel==12 then curBG=customRange.bg[customSel[12]] elseif sel==13 then BGM(customRange.bgm[customSel[13]]) end elseif key=="right"then customSel[sel]=customSel[sel]%#customRange[customID[sel]]+1 if sel==12 then curBG=customRange.bg[customSel[sel]] elseif sel==13 then BGM(customRange.bgm[customSel[sel]]) end elseif key=="down"then sel=sel%#customID+1 elseif key=="up"then sel=(sel-2)%#customID+1 elseif key=="d"then gotoScene("draw") elseif key=="return"then loadGame(0,1) elseif key=="space"then loadGame(0,2) elseif key=="escape"then back() end end function mouseDown.draw(x,y,k) mouseMove.draw(x,y) end function mouseMove.draw(x,y,dx,dy) sx,sy=int((x-200)/30)+1,20-int((y-60)/30) if sx<1 or sx>10 then sx=nil end if sy<1 or sy>20 then sy=nil end if sx and sy and ms.isDown(1,2,3)then preField[sy][sx]=ms.isDown(1)and pen or ms.isDown(2)and -1 or 0 end end function wheelmoved.draw(x,y) if y<0 then pen=pen+1 if pen==8 then pen=9 elseif pen==14 then pen=0 end else pen=pen-1 if pen==8 then pen=7 elseif pen==-1 then pen=13 end end end function touchDown.draw(id,x,y) mouseMove.draw(x,y) end function touchMove.draw(id,x,y,dx,dy) sx,sy=int((x-200)/30)+1,20-int((y-60)/30) if sx<1 or sx>10 then sx=nil end if sy<1 or sy>20 then sy=nil end if sx and sy then preField[sy][sx]=pen end end function keyDown.draw(key) if key=="delete"then if clearSureTime>15 then for y=1,20 do for x=1,10 do preField[y][x]=0 end end clearSureTime=0 else clearSureTime=50 end elseif key=="up"or key=="down"or key=="left"or key=="right"then if not sx then sx=1 end if not sy then sy=1 end if key=="up"and sy<20 then sy=sy+1 elseif key=="down"and sy>1 then sy=sy-1 elseif key=="left"and sx>1 then sx=sx-1 elseif key=="right"and sx<10 then sx=sx+1 end if kb.isDown("space")then preField[sy][sx]=pen end elseif key=="space"then if sx and sy then preField[sy][sx]=pen end elseif key=="tab"then pen=-1 elseif key=="backspace"or key=="lalt"then pen=0 elseif key=="escape"then back() else pen=find("123qwea#sdzxc",key)or pen end end function keyDown.setting2(key) if key=="escape"then if keyboardSetting then keyboardSetting=false else back() end elseif keyboardSetting then for l=1,8 do for y=1,13 do if setting.keyMap[l][y]==key then setting.keyMap[l][y]="" end end end setting.keyMap[curBoard][keyboardSet]=key keyboardSetting=false elseif key=="return"then keyboardSetting=true elseif key=="up"then keyboardSet=max(keyboardSet-1,1) elseif key=="down"then keyboardSet=min(keyboardSet+1,13) elseif key=="left"then curBoard=max(curBoard-1,1) elseif key=="right"then curBoard=min(curBoard+1,8) end end function gamepadDown.setting2(key) if key=="back"then if joystickSetting then joystickSetting=false else back() end elseif joystickSetting then for l=9,16 do for y=1,12 do if setting.keyMap[l][y]==key then setting.keyMap[l][y]="" end end end setting.keyMap[8+curBoard][joystickSet]=key joystickSetting=false elseif key=="start"then joystickSetting=true elseif key=="up"then joystickSet=max(joystickSet-1,1) elseif key=="down"then joystickSet=min(joystickSet+1,12) elseif key=="left"then curBoard=max(curBoard-1,1) elseif key=="right"then curBoard=min(curBoard+1,8) end end function mouseDown.setting3(x,y,k) if k==2 then back()end for K=1,#virtualkey do local b=virtualkey[K] if (x-b[1])^2+(y-b[2])^21 then sel=sel-1 end elseif key=="right"then if sel<#updateLog then sel=sel+1 end elseif key=="escape"then back() end end ------------------------------------------------------------- function love.mousepressed(x,y,k,t,num) if t then return end mouseShow=true mx,my=xOy:inverseTransformPoint(x,y) if mouseDown[scene]then mouseDown[scene](mx,my,k) elseif k==2 then back() end if k==1 then if not sceneSwaping and Widget.sel then local W=Widget.sel if W.type=="button"then W.code() W.alpha=1 Widget.sel=nil love.mousemoved(x,y,0,0) SFX("button") VOICE("nya") VIB(1) end end end end function love.mousemoved(x,y,dx,dy,t) if t then return end mouseShow=true mx,my=xOy:inverseTransformPoint(x,y) Widget.sel=nil if mouseMove[scene]then mouseMove[scene](mx,my,dx/scr.k,dy/scr.k) end for _,W in next,Widget[scene]do if not(W.hide and W.hide())then if W.type=="button"then if mx>W.x and mxW.y and myW.x and xW.y and y=.5625 then scr.k=w/1280 scr.x,scr.y=0,(h-w*9/16)*.5 else scr.k=h/720 scr.x,scr.y=(w-h*16/9)*.5,0 end gc.origin() xOy=xOy:setTransformation(w*.5,h*.5,nil,scr.k,nil,640,360) gc.replaceTransform(xOy) collectgarbage() end function love.focus(f) if system~="Android" and not f and scene=="play"then pauseGame()end end function love.update(dt) -- if players then for k,v in pairs(players[1])do -- if rawget(_G,k)and k~="next"and k~="hold"and k~="stat"then print(k,_G[v])end -- end end--check player data flew(debugging) for i=#BGblock,1,-1 do BGblock[i].y=BGblock[i].y+BGblock[i].v if BGblock[i].y>720 then rem(BGblock,i)end end if setting.bgblock then BGblock.tm=BGblock.tm-1 if BGblock.tm==0 then BGblock[#BGblock+1]=getNewBlock() BGblock.tm=rnd(20,30) end end if sceneSwaping then sceneSwaping.time=sceneSwaping.time-1 if sceneSwaping.time==sceneSwaping.mid then for k,W in next,Widget[scene]do if W.type=="button"then W.alpha=0 end--Reset widgets' alpha end Widget.sel=nil scene=sceneSwaping.tar sceneInit[scene]() --scene swapped! elseif sceneSwaping.time==0 then sceneSwaping=nil end end if Tmr[scene]then Tmr[scene](dt) end for i=#Task,1,-1 do Task[i]:update() end if voicePlaying[1]then if not voicePlaying[1]:isPlaying()then rem(voicePlaying,1) end if voicePlaying[1] and not voicePlaying[1]:isPlaying()then voicePlaying[1]:play()end end for k,W in next,Widget[scene]do if W.type=="button"then local t=W==Widget.sel and .4 or 0 W.alpha=abs(W.alpha-t)>.02 and(W.alpha+(W.alphat then W.alpha=W.alpha-.02 elseif W.alpha.5625 then local d=(scr.h-scr.w*9/16)*.5/scr.k gc.rectangle("fill",0,0,1280,-d) gc.rectangle("fill",0,720,1280,d) else--high local d=(scr.w-scr.h*16/9)*.5/scr.k gc.rectangle("fill",0,0,-d,720) gc.rectangle("fill",1280,0,d,720) end--wide end--Black side gc.setColor(1,1,1) if powerInfoCanvas and scene~="draw"then gc.draw(powerInfoCanvas) end setFont(20) gc.print(tm.getFPS(),5,700) if devMode>0 then if devMode==2 then gc.setColor(1,1,0) end gc.print(mx.." "..my,5,640) gc.print(#freeRow.."/"..freeRow.L,5,660) gc.print(gcinfo(),5,680) end end function love.run() local lastFrame,lastUpdatePowerInfo=Timer(),Timer() local readyDrawFrame=0 local PUMP,POLL=love.event.pump,love.event.poll love.resize(gc.getWidth(),gc.getHeight()) scene="load"sceneInit.load()--System Launch return function() PUMP() for N,a,b,c,d,e in POLL()do if N=="quit"then destroyPlayers()return 0 elseif love[N]then love[N](a,b,c,d,e)end end tm.step() love.update(tm.getDelta()) if not wd.isMinimized()then readyDrawFrame=readyDrawFrame+setting.frameMul if readyDrawFrame>=100 then readyDrawFrame=readyDrawFrame-100 love.draw() gc.present() end end repeat if Timer()-lastUpdatePowerInfo>5 then updatePowerInfo() lastUpdatePowerInfo=Timer() end until Timer()-lastFrame>.0133 tm.sleep(.003) lastFrame=Timer() end end userData,userSetting=fs.newFile("userdata"),fs.newFile("usersetting") if fs.getInfo("userdata")then loadData() end if fs.getInfo("usersetting")then loadSetting() elseif system=="Android" or system=="iOS"then setting.virtualkeySwitch=true setting.swap=false end math.randomseed(os.time()*626) swapLanguage(setting.lang) changeBlockSkin(setting.skin)