整理代码,删掉多个goto
This commit is contained in:
@@ -198,63 +198,67 @@ function love.touchreleased(id,x,y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(i)
|
local function noDevkeyPressed(key)
|
||||||
mouseShow=false
|
if key=="f1"then
|
||||||
if devMode then
|
PROFILE.switch()
|
||||||
if i=="f1"then PROFILE.switch()
|
elseif key=="f2"then
|
||||||
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))
|
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
|
elseif key=="f3"then
|
||||||
for _=1,8 do
|
for _=1,8 do
|
||||||
local P=PLAYERS.alive[rnd(#PLAYERS.alive)]
|
local P=PLAYERS.alive[rnd(#PLAYERS.alive)]
|
||||||
if P~=PLAYERS[1]then
|
if P~=PLAYERS[1]then
|
||||||
P.lastRecv=PLAYERS[1]
|
P.lastRecv=PLAYERS[1]
|
||||||
P:lose()
|
P:lose()
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elseif i=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
|
end
|
||||||
elseif i=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end
|
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
|
||||||
elseif i=="f6"then for k,v in next,_G do DBP(k,v)end
|
elseif key=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end
|
||||||
elseif i=="f7"then if love._openConsole then love._openConsole()end
|
elseif key=="f6"then for k,v in next,_G do DBP(k,v)end
|
||||||
elseif i=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow)
|
elseif key=="f7"then if love._openConsole then love._openConsole()end
|
||||||
elseif i=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow)
|
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow)
|
||||||
elseif i=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow)
|
elseif key=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow)
|
||||||
elseif i=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow)
|
elseif key=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow)
|
||||||
elseif i=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow)
|
elseif key=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow)
|
||||||
elseif i=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
|
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow)
|
||||||
elseif devMode==2 then
|
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
|
||||||
if WIDGET.sel then
|
elseif devMode==2 then
|
||||||
local W=WIDGET.sel
|
if WIDGET.sel then
|
||||||
if i=="left"then W.x=W.x-10
|
local W=WIDGET.sel
|
||||||
elseif i=="right"then W.x=W.x+10
|
if key=="left"then W.x=W.x-10
|
||||||
elseif i=="up"then W.y=W.y-10
|
elseif key=="right"then W.x=W.x+10
|
||||||
elseif i=="down"then W.y=W.y+10
|
elseif key=="up"then W.y=W.y-10
|
||||||
elseif i==","then W.w=W.w-10
|
elseif key=="down"then W.y=W.y+10
|
||||||
elseif i=="."then W.w=W.w+10
|
elseif key==","then W.w=W.w-10
|
||||||
elseif i=="/"then W.h=W.h-10
|
elseif key=="."then W.w=W.w+10
|
||||||
elseif i=="'"then W.h=W.h+10
|
elseif key=="/"then W.h=W.h-10
|
||||||
elseif i=="["then W.font=W.font-1
|
elseif key=="'"then W.h=W.h+10
|
||||||
elseif i=="]"then W.font=W.font+1
|
elseif key=="["then W.font=W.font-1
|
||||||
else goto NORMAL
|
elseif key=="]"then W.font=W.font+1
|
||||||
end
|
else return true
|
||||||
else
|
|
||||||
goto NORMAL
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
goto NORMAL
|
return true
|
||||||
end
|
end
|
||||||
return
|
else
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
::NORMAL::
|
end
|
||||||
if i=="f8"then
|
function love.keypressed(key)
|
||||||
|
mouseShow=false
|
||||||
|
if devMode and not noDevkeyPressed(key)then
|
||||||
|
return
|
||||||
|
elseif key=="f8"then
|
||||||
devMode=1
|
devMode=1
|
||||||
LOG.print("DEBUG ON",COLOR.yellow)
|
LOG.print("DEBUG ON",COLOR.yellow)
|
||||||
elseif i=="f11"then
|
elseif key=="f11"then
|
||||||
switchFullscreen()
|
switchFullscreen()
|
||||||
else
|
elseif not SCN.swapping then
|
||||||
if SCN.swapping then return end
|
if SCN.keyDown then
|
||||||
if SCN.keyDown then SCN.keyDown(i)
|
SCN.keyDown(key)
|
||||||
elseif i=="escape"then SCN.back()
|
elseif key=="escape"then
|
||||||
else WIDGET.keyPressed(i)
|
SCN.back()
|
||||||
|
else
|
||||||
|
WIDGET.keyPressed(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
47
parts/ai.lua
47
parts/ai.lua
@@ -224,37 +224,36 @@ return{
|
|||||||
else
|
else
|
||||||
bn=P.holdQueue[1]and P.holdQueue[1].id or P.nextQueue[1]and P.nextQueue[1].id
|
bn=P.holdQueue[1]and P.holdQueue[1].id or P.nextQueue[1]and P.nextQueue[1].id
|
||||||
end
|
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
|
--Move to bottom
|
||||||
local cb=BLOCKS[bn][dir]
|
while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do
|
||||||
for cx=1,11-#cb[1]do--Each pos
|
cy=cy-1
|
||||||
local cy=#Tfield+1
|
end
|
||||||
|
|
||||||
--Move to bottom
|
--Simulate lock
|
||||||
while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do
|
for i=1,#cb do
|
||||||
cy=cy-1
|
local y=cy+i-1
|
||||||
end
|
if not Tfield[y]then Tfield[y]=getRow(0)end
|
||||||
|
local L=Tfield[y]
|
||||||
--Simulate lock
|
for j=1,#cb[1]do
|
||||||
for i=1,#cb do
|
if cb[i][j]then
|
||||||
local y=cy+i-1
|
L[cx+j-1]=1
|
||||||
if not Tfield[y]then Tfield[y]=getRow(0)end
|
end
|
||||||
local L=Tfield[y]
|
|
||||||
for j=1,#cb[1]do
|
|
||||||
if cb[i][j]then
|
|
||||||
L[cx+j-1]=1
|
|
||||||
end
|
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
|
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
|
||||||
end
|
end
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
if not best.bn then return 1 end
|
if not best.bn then return 1 end
|
||||||
|
|
||||||
|
|||||||
@@ -79,14 +79,14 @@ local loadingThread=coroutine.create(function()
|
|||||||
{"rect","fill",10,4,-2,23},
|
{"rect","fill",10,4,-2,23},
|
||||||
{"poly","fill",10,4,24,10,10,16.5},
|
{"poly","fill",10,4,24,10,10,16.5},
|
||||||
{"rect","fill",4,24,10,3},
|
{"rect","fill",4,24,10,3},
|
||||||
}
|
}YIELD()
|
||||||
modeIcons.tsd=DOGC{64,64,
|
modeIcons.tsd=DOGC{64,64,
|
||||||
{"rect","fill",7,7,16,16},
|
{"rect","fill",7,7,16,16},
|
||||||
{"rect","fill",7,41,16,16},
|
{"rect","fill",7,41,16,16},
|
||||||
{"rect","fill",41,41,16,16},
|
{"rect","fill",41,41,16,16},
|
||||||
{"move",.5,.5},
|
{"move",.5,.5},
|
||||||
{"poly","line",7,24,56,24,56,39,39,39,39,56,24,56,24,39,7,39},
|
{"poly","line",7,24,56,24,56,39,39,39,39,56,24,56,24,39,7,39},
|
||||||
}
|
}YIELD()
|
||||||
modeIcons.infinite=DOGC{64,64,
|
modeIcons.infinite=DOGC{64,64,
|
||||||
{"wid",4},
|
{"wid",4},
|
||||||
{"circ","line",32,32,28},
|
{"circ","line",32,32,28},
|
||||||
@@ -97,7 +97,7 @@ local loadingThread=coroutine.create(function()
|
|||||||
{"rect","fill",7,30,4,4},
|
{"rect","fill",7,30,4,4},
|
||||||
{"rect","fill",52,30,4,4},
|
{"rect","fill",52,30,4,4},
|
||||||
{"rect","fill",30,52,4,4},
|
{"rect","fill",30,52,4,4},
|
||||||
}
|
}YIELD()
|
||||||
modeIcons.t49=DOGC{64,64,
|
modeIcons.t49=DOGC{64,64,
|
||||||
{"wid",2},
|
{"wid",2},
|
||||||
{"rect","line",05,05,10,20},{"rect","line",49,05,10,20},
|
{"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},
|
{"rect","line",20,10,23,43},
|
||||||
{"rgb",1,1,1,.7},
|
{"rgb",1,1,1,.7},
|
||||||
{"rect","fill",20,10,23,43},
|
{"rect","fill",20,10,23,43},
|
||||||
}
|
}YIELD()
|
||||||
modeIcons.t99=DOGC{64,64,
|
modeIcons.t99=DOGC{64,64,
|
||||||
{"wid",2},
|
{"wid",2},
|
||||||
{"rect","line",02,02,6,12},{"rect","line",11,02,6,12},
|
{"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},
|
{"rect","line",20,10,23,43},
|
||||||
{"rgb",1,1,1,.7},
|
{"rgb",1,1,1,.7},
|
||||||
{"rect","fill",20,10,23,43},
|
{"rect","fill",20,10,23,43},
|
||||||
}
|
}YIELD()
|
||||||
|
|
||||||
upFloor()
|
upFloor()
|
||||||
for i=1,#MODES do
|
for i=1,#MODES do
|
||||||
@@ -248,19 +248,10 @@ function scene.update(dt)
|
|||||||
if not locked then
|
if not locked then
|
||||||
if progress<25 then
|
if progress<25 then
|
||||||
local p=progress
|
local p=progress
|
||||||
::again::
|
repeat
|
||||||
if loadingThread then
|
|
||||||
assert(coroutine.resume(loadingThread))
|
assert(coroutine.resume(loadingThread))
|
||||||
else
|
until not loadingThread or skip<=0 or progress~=p
|
||||||
return
|
if skip>0 then skip=skip-1 end
|
||||||
end
|
|
||||||
if skip>0 then
|
|
||||||
if progress==p then
|
|
||||||
goto again
|
|
||||||
else
|
|
||||||
skip=skip-1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
openTime=openTime+dt
|
openTime=openTime+dt
|
||||||
if skip>0 then
|
if skip>0 then
|
||||||
|
|||||||
@@ -194,6 +194,15 @@ local baseRankColor={
|
|||||||
{.85,.8,.3,.3},
|
{.85,.8,.3,.3},
|
||||||
{.4,.7,.4,.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()
|
function scene.draw()
|
||||||
local _
|
local _
|
||||||
gc.push("transform")
|
gc.push("transform")
|
||||||
@@ -225,22 +234,11 @@ function scene.draw()
|
|||||||
local rank=R[name]
|
local rank=R[name]
|
||||||
local S=M.size
|
local S=M.size
|
||||||
|
|
||||||
--Frame & fill
|
--Draw shapes on map
|
||||||
gc.setColor(baseRankColor[rank])
|
gc.setColor(baseRankColor[rank])
|
||||||
local drawType="fill"
|
drawModeShape(M,S,"fill")
|
||||||
::again::
|
gc.setColor(1,1,sel==name and 0 or 1)
|
||||||
if M.shape==1 then--Rectangle
|
drawModeShape(M,S,"line")
|
||||||
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
|
|
||||||
|
|
||||||
--Icon
|
--Icon
|
||||||
local icon=M.icon
|
local icon=M.icon
|
||||||
|
|||||||
Reference in New Issue
Block a user