From 390d2a42b8864174b77195cb15b00391ca358421 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 25 Mar 2021 02:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E5=88=A0=E6=8E=89=E5=A4=9A=E4=B8=AAgoto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 102 ++++++++++++++++++++++-------------------- parts/ai.lua | 47 ++++++++++--------- parts/scenes/load.lua | 25 ++++------- parts/scenes/mode.lua | 28 ++++++------ 4 files changed, 97 insertions(+), 105 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index b9d52a9d..c1137aef 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -198,63 +198,67 @@ function love.touchreleased(id,x,y) end end -function love.keypressed(i) - mouseShow=false - if devMode then - if i=="f1"then PROFILE.switch() - elseif i=="f2"then LOG.print(string.format("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s",SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num)) - elseif i=="f3"then - for _=1,8 do - local P=PLAYERS.alive[rnd(#PLAYERS.alive)] - if P~=PLAYERS[1]then - P.lastRecv=PLAYERS[1] - P:lose() - end +local function noDevkeyPressed(key) + if key=="f1"then + PROFILE.switch() + elseif key=="f2"then + LOG.print(string.format("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s",SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num)) + elseif key=="f3"then + for _=1,8 do + local P=PLAYERS.alive[rnd(#PLAYERS.alive)] + if P~=PLAYERS[1]then + P.lastRecv=PLAYERS[1] + P:lose() end - elseif i=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end - elseif i=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end - elseif i=="f6"then for k,v in next,_G do DBP(k,v)end - elseif i=="f7"then if love._openConsole then love._openConsole()end - elseif i=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow) - elseif i=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow) - elseif i=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow) - elseif i=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow) - elseif i=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow) - elseif i=="\\"then _G["\100\114\97\119\70\87\77"]=NULL - elseif devMode==2 then - if WIDGET.sel then - local W=WIDGET.sel - if i=="left"then W.x=W.x-10 - elseif i=="right"then W.x=W.x+10 - elseif i=="up"then W.y=W.y-10 - elseif i=="down"then W.y=W.y+10 - elseif i==","then W.w=W.w-10 - elseif i=="."then W.w=W.w+10 - elseif i=="/"then W.h=W.h-10 - elseif i=="'"then W.h=W.h+10 - elseif i=="["then W.font=W.font-1 - elseif i=="]"then W.font=W.font+1 - else goto NORMAL - end - else - goto NORMAL + end + elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end + elseif key=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end + elseif key=="f6"then for k,v in next,_G do DBP(k,v)end + elseif key=="f7"then if love._openConsole then love._openConsole()end + elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow) + elseif key=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow) + elseif key=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow) + elseif key=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow) + elseif key=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow) + elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL + elseif devMode==2 then + if WIDGET.sel then + local W=WIDGET.sel + if key=="left"then W.x=W.x-10 + elseif key=="right"then W.x=W.x+10 + elseif key=="up"then W.y=W.y-10 + elseif key=="down"then W.y=W.y+10 + elseif key==","then W.w=W.w-10 + elseif key=="."then W.w=W.w+10 + elseif key=="/"then W.h=W.h-10 + elseif key=="'"then W.h=W.h+10 + elseif key=="["then W.font=W.font-1 + elseif key=="]"then W.font=W.font+1 + else return true end else - goto NORMAL + return true end - return + else + return true end - ::NORMAL:: - if i=="f8"then +end +function love.keypressed(key) + mouseShow=false + if devMode and not noDevkeyPressed(key)then + return + elseif key=="f8"then devMode=1 LOG.print("DEBUG ON",COLOR.yellow) - elseif i=="f11"then + elseif key=="f11"then switchFullscreen() - else - if SCN.swapping then return end - if SCN.keyDown then SCN.keyDown(i) - elseif i=="escape"then SCN.back() - else WIDGET.keyPressed(i) + elseif not SCN.swapping then + if SCN.keyDown then + SCN.keyDown(key) + elseif key=="escape"then + SCN.back() + else + WIDGET.keyPressed(key) end end end diff --git a/parts/ai.lua b/parts/ai.lua index c0d19197..1e6c4c4f 100644 --- a/parts/ai.lua +++ b/parts/ai.lua @@ -224,37 +224,36 @@ return{ else bn=P.holdQueue[1]and P.holdQueue[1].id or P.nextQueue[1]and P.nextQueue[1].id end - if not bn then goto continue end + if bn then + for dir=0,dirCount[bn]do--Each dir + local cb=BLOCKS[bn][dir] + for cx=1,11-#cb[1]do--Each pos + local cy=#Tfield+1 - for dir=0,dirCount[bn]do--Each dir - local cb=BLOCKS[bn][dir] - for cx=1,11-#cb[1]do--Each pos - local cy=#Tfield+1 + --Move to bottom + while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do + cy=cy-1 + end - --Move to bottom - while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do - cy=cy-1 - end - - --Simulate lock - for i=1,#cb do - local y=cy+i-1 - if not Tfield[y]then Tfield[y]=getRow(0)end - local L=Tfield[y] - for j=1,#cb[1]do - if cb[i][j]then - L[cx+j-1]=1 + --Simulate lock + for i=1,#cb do + local y=cy+i-1 + if not Tfield[y]then Tfield[y]=getRow(0)end + local L=Tfield[y] + for j=1,#cb[1]do + if cb[i][j]then + L[cx+j-1]=1 + end end end + local score=getScore(Tfield,cb,cy) + if score>best.score then + best={bn=bn,x=cx,dir=dir,hold=ifhold==1,score=score} + end + resetField(field_org,Tfield,cy) end - local score=getScore(Tfield,cb,cy) - if score>best.score then - best={bn=bn,x=cx,dir=dir,hold=ifhold==1,score=score} - end - resetField(field_org,Tfield,cy) end end - ::continue:: end if not best.bn then return 1 end diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index c59e98d8..c6633031 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -79,14 +79,14 @@ local loadingThread=coroutine.create(function() {"rect","fill",10,4,-2,23}, {"poly","fill",10,4,24,10,10,16.5}, {"rect","fill",4,24,10,3}, - } + }YIELD() modeIcons.tsd=DOGC{64,64, {"rect","fill",7,7,16,16}, {"rect","fill",7,41,16,16}, {"rect","fill",41,41,16,16}, {"move",.5,.5}, {"poly","line",7,24,56,24,56,39,39,39,39,56,24,56,24,39,7,39}, - } + }YIELD() modeIcons.infinite=DOGC{64,64, {"wid",4}, {"circ","line",32,32,28}, @@ -97,7 +97,7 @@ local loadingThread=coroutine.create(function() {"rect","fill",7,30,4,4}, {"rect","fill",52,30,4,4}, {"rect","fill",30,52,4,4}, - } + }YIELD() modeIcons.t49=DOGC{64,64, {"wid",2}, {"rect","line",05,05,10,20},{"rect","line",49,05,10,20}, @@ -105,7 +105,7 @@ local loadingThread=coroutine.create(function() {"rect","line",20,10,23,43}, {"rgb",1,1,1,.7}, {"rect","fill",20,10,23,43}, - } + }YIELD() modeIcons.t99=DOGC{64,64, {"wid",2}, {"rect","line",02,02,6,12},{"rect","line",11,02,6,12}, @@ -119,7 +119,7 @@ local loadingThread=coroutine.create(function() {"rect","line",20,10,23,43}, {"rgb",1,1,1,.7}, {"rect","fill",20,10,23,43}, - } + }YIELD() upFloor() for i=1,#MODES do @@ -248,19 +248,10 @@ function scene.update(dt) if not locked then if progress<25 then local p=progress - ::again:: - if loadingThread then + repeat assert(coroutine.resume(loadingThread)) - else - return - end - if skip>0 then - if progress==p then - goto again - else - skip=skip-1 - end - end + until not loadingThread or skip<=0 or progress~=p + if skip>0 then skip=skip-1 end else openTime=openTime+dt if skip>0 then diff --git a/parts/scenes/mode.lua b/parts/scenes/mode.lua index dd06e888..0a3c6e4e 100644 --- a/parts/scenes/mode.lua +++ b/parts/scenes/mode.lua @@ -194,6 +194,15 @@ local baseRankColor={ {.85,.8,.3,.3}, {.4,.7,.4,.3}, } +local function drawModeShape(M,S,drawType) + if M.shape==1 then--Rectangle + gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S) + elseif M.shape==2 then--Diamond + gc.circle(drawType,M.x,M.y,S+12,4) + elseif M.shape==3 then--Octagon + gc.circle(drawType,M.x,M.y,S+6,8) + end +end function scene.draw() local _ gc.push("transform") @@ -225,22 +234,11 @@ function scene.draw() local rank=R[name] local S=M.size - --Frame & fill + --Draw shapes on map gc.setColor(baseRankColor[rank]) - local drawType="fill" - ::again:: - if M.shape==1 then--Rectangle - gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S) - elseif M.shape==2 then--Diamond - gc.circle(drawType,M.x,M.y,S+12,4) - elseif M.shape==3 then--Octagon - gc.circle(drawType,M.x,M.y,S+6,8) - end - if drawType=="fill"then - gc.setColor(1,1,sel==name and 0 or 1) - drawType="line" - goto again - end + drawModeShape(M,S,"fill") + gc.setColor(1,1,sel==name and 0 or 1) + drawModeShape(M,S,"line") --Icon local icon=M.icon