整理代码,大量绘制玩家组件的函数可以传入具体参数而不是就一个玩家对象

This commit is contained in:
MrZ626
2021-08-18 23:40:11 +08:00
parent 273de18ae3
commit 8c4f380d73

View File

@@ -210,75 +210,66 @@ local function drawFXs(P)
end end
end end
local drawGhost={ local drawGhost={
color=function(P,clr,alpha) color=function(CB,curX,ghoY,alpha,texture,clr)
gc_setColor(1,1,1,alpha) gc_setColor(1,1,1,alpha)
local texture=P.skinLib
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_draw(texture[clr],30*(j+P.curX-1)-30,-30*(i+P.ghoY-1)) gc_draw(texture[clr],30*(j+curX-1)-30,-30*(i+ghoY-1))
end end
end end end end
end, end,
gray=function(P,_,alpha) gray=function(CB,curX,ghoY,alpha,texture,_)
gc_setColor(1,1,1,alpha) gc_setColor(1,1,1,alpha)
local texture=P.skinLib
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_draw(texture[21],30*(j+P.curX-1)-30,-30*(i+P.ghoY-1)) gc_draw(texture[21],30*(j+curX-1)-30,-30*(i+ghoY-1))
end end
end end end end
end, end,
colorCell=function(P,clr,alpha) colorCell=function(CB,curX,ghoY,alpha,_,clr)
clr=minoColor[clr] clr=minoColor[clr]
gc_setColor(clr[1],clr[2],clr[3],alpha) gc_setColor(clr[1],clr[2],clr[3],alpha)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_rectangle('fill',30*(j+P.curX-1)-30,-30*(i+P.ghoY-1),30,30) gc_rectangle('fill',30*(j+curX-1)-30,-30*(i+ghoY-1),30,30)
end end
end end end end
end, end,
grayCell=function(P,_,alpha) grayCell=function(CB,curX,ghoY,alpha,_,_)
gc_setColor(1,1,1,alpha) gc_setColor(1,1,1,alpha)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_rectangle('fill',30*(j+P.curX-1)-30,-30*(i+P.ghoY-1),30,30) gc_rectangle('fill',30*(j+curX-1)-30,-30*(i+ghoY-1),30,30)
end end
end end end end
end, end,
colorLine=function(P,clr,alpha) colorLine=function(CB,curX,ghoY,alpha,_,clr)
clr=minoColor[clr] clr=minoColor[clr]
gc_setColor(clr[1],clr[2],clr[3],alpha) gc_setColor(clr[1],clr[2],clr[3],alpha)
gc_setLineWidth(4) gc_setLineWidth(4)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_rectangle('line',30*(j+P.curX-1)-30+4,-30*(i+P.ghoY-1)+4,22,22) gc_rectangle('line',30*(j+curX-1)-30+4,-30*(i+ghoY-1)+4,22,22)
end end
end end end end
end, end,
grayLine=function(P,_,alpha) grayLine=function(CB,curX,ghoY,alpha,_,_)
gc_setColor(1,1,1,alpha) gc_setColor(1,1,1,alpha)
gc_setLineWidth(4) gc_setLineWidth(4)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_rectangle('line',30*(j+P.curX-1)-30+4,-30*(i+P.ghoY-1)+4,22,22) gc_rectangle('line',30*(j+curX-1)-30+4,-30*(i+ghoY-1)+4,22,22)
end end
end end end end
end, end,
} }
local function drawBlockOutline(P,texture,trans) local function drawBlockOutline(CB,curX,curY,texture,trans)
shader_alpha:send('a',trans) shader_alpha:send('a',trans)
gc_setShader(shader_alpha) gc_setShader(shader_alpha)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
local x=30*(j+P.curX)-60-3 local x=30*(j+curX)-60-3
local y=30-30*(i+P.curY)-3 local y=30-30*(i+curY)-3
gc_draw(texture,x,y) gc_draw(texture,x,y)
gc_draw(texture,x+6,y+6) gc_draw(texture,x+6,y+6)
gc_draw(texture,x+6,y) gc_draw(texture,x+6,y)
@@ -287,30 +278,27 @@ local function drawBlockOutline(P,texture,trans)
end end end end
gc_setShader() gc_setShader()
end end
local function drawBlockShade(P,alpha) local function drawBlockShade(CB,curX,curY,alpha)
gc_setColor(1,1,1,alpha) gc_setColor(1,1,1,alpha)
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_rectangle('fill',30*(j+P.curX)-60,30-30*(i+P.curY),30,30) gc_rectangle('fill',30*(j+curX)-60,30-30*(i+curY),30,30)
end end
end end end end
end end
local function drawBlock(P,clr) local function drawBlock(CB,curX,curY,texture)
gc_setColor(1,1,1) gc_setColor(1,1,1)
gc_setShader(shader_blockSatur) gc_setShader(shader_blockSatur)
local texture=P.skinLib[clr]
local CB=P.cur.bk
for i=1,#CB do for j=1,#CB[1]do for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then if CB[i][j]then
gc_draw(texture,30*(j+P.curX-1)-30,-30*(i+P.curY-1)) gc_draw(texture,30*(j+curX-1)-30,-30*(i+curY-1))
end end
end end end end
gc_setShader() gc_setShader()
end end
local function drawNextPreview(P,B) local function drawNextPreview(B,fieldH,fieldBeneath)
gc_setColor(1,1,1,.8) gc_setColor(1,1,1,.8)
local y=int(P.gameEnv.fieldH+1-modf(B.sc[1]))+ceil(P.fieldBeneath/30) local y=int(fieldH+1-modf(B.sc[1]))+ceil(fieldBeneath/30)
B=B.bk B=B.bk
local x=int(6-#B[1]*.5) local x=int(6-#B[1]*.5)
local cross=TEXTURE.puzzleMark[-1] local cross=TEXTURE.puzzleMark[-1]
@@ -320,10 +308,10 @@ local function drawNextPreview(P,B)
end end
end end end end
end end
local function drawBuffer(P) local function drawBuffer(atkBuffer,bufferWarn,atkBufferSum1,atkBufferSum)
local h=0 local h=0
for i=1,#P.atkBuffer do for i=1,#atkBuffer do
local A=P.atkBuffer[i] local A=atkBuffer[i]
local bar=A.amount*30 local bar=A.amount*30
if h+bar>600 then bar=600-h end if h+bar>600 then bar=600-h end
if not A.sent then if not A.sent then
@@ -356,8 +344,8 @@ local function drawBuffer(P)
end end
h=h+bar h=h+bar
end end
if P.gameEnv.bufferWarn then if bufferWarn then
local sum=P.atkBufferSum1 local sum=atkBufferSum1
if sum>=8 then if sum>=8 then
gc_push('transform') gc_push('transform')
gc_translate(300,max(0,600-30*sum)) gc_translate(300,max(0,600-30*sum))
@@ -365,7 +353,7 @@ local function drawBuffer(P)
gc_setColor(1,.2+min(sum*.02,.8)*(.5+.5*sin(TIME()*min(sum,32))),.2,min(sum/30,.8)) gc_setColor(1,.2+min(sum*.02,.8)*(.5+.5*sin(TIME()*min(sum,32))),.2,min(sum/30,.8))
setFont(100) setFont(100)
if sum>20 then if sum>20 then
local d=P.atkBufferSum-sum local d=atkBufferSum-sum
if d>.5 then if d>.5 then
gc_translate(d^.5*(rnd()-.5)*15,d^.5*(rnd()-.5)*15) gc_translate(d^.5*(rnd()-.5)*15,d^.5*(rnd()-.5)*15)
end end
@@ -375,13 +363,13 @@ local function drawBuffer(P)
end end
end end
end end
local function drawB2Bbar(P) local function drawB2Bbar(b2b,b2b1)
local a,b=P.b2b,P.b2b1 local a,b=b2b,b2b1
if a>b then a,b=b,a end if a>b then a,b=b,a end
if b>=0 then if b>0 then
gc_setColor(.8,1,.2) gc_setColor(.8,1,.2)
gc_rectangle('fill',-14,600-b*.6,11,b*.6,2) gc_rectangle('fill',-14,600-b*.6,11,b*.6,2)
gc_setColor(P.b2b<50 and COLOR.Z or P.b2b<=800 and COLOR.lR or COLOR.lB) gc_setColor(b2b<50 and COLOR.Z or b2b<=800 and COLOR.lR or COLOR.lB)
gc_rectangle('fill',-14,600-a*.6,11,a*.6,2) gc_rectangle('fill',-14,600-a*.6,11,a*.6,2)
if TIME()%.5<.3 then if TIME()%.5<.3 then
gc_setColor(1,1,1) gc_setColor(1,1,1)
@@ -389,39 +377,35 @@ local function drawB2Bbar(P)
end end
end end
end end
local function drawLDI(P,ENV)--Lock Delay Indicator local function drawLDI(easyFresh,length,freshTime)--Lock Delay Indicator
if ENV.easyFresh then if easyFresh then
gc_setColor(.97,.97,.97) gc_setColor(.97,.97,.97)
else else
gc_setColor(1,.5,.5) gc_setColor(1,.5,.5)
end end
if P.lockDelay>=0 then if length>=0 then
gc_rectangle('fill',0,602,300*P.lockDelay/ENV.lock,4) gc_rectangle('fill',0,602,300*length,4)
end end
if P.freshTime>0 then if freshTime>0 then
LDmarks:setDrawRange(1,min(P.freshTime,15)) LDmarks:setDrawRange(1,min(freshTime,15))
gc_draw(LDmarks) gc_draw(LDmarks)
end end
end end
local function drawHold(P) local function drawHold(holdQueue,holdCount,holdTime,skinLib)
local ENV=P.gameEnv local N=holdCount*72
if ENV.holdCount==0 then return end
local holdQueue=P.holdQueue
local N=ENV.holdCount*72
gc_push('transform') gc_push('transform')
gc_translate(12,20) gc_translate(12,20)
gc_setLineWidth(2) gc_setLineWidth(2)
gc_setColor(0,0,0,.4)gc_rectangle('fill',0,0,100,N+8,5) gc_setColor(0,0,0,.4)gc_rectangle('fill',0,0,100,N+8,5)
gc_setColor(.97,.97,.97)gc_rectangle('line',0,0,100,N+8,5) gc_setColor(.97,.97,.97)gc_rectangle('line',0,0,100,N+8,5)
N=#holdQueue<ENV.holdCount and P.nextQueue[1]and 1 or P.holdTime+1 N=#holdQueue<holdCount and holdQueue[1]and 1 or holdTime+1
gc_push('transform') gc_push('transform')
gc_translate(50,40) gc_translate(50,40)
gc_setShader(shader_blockSatur) gc_setShader(shader_blockSatur)
for n=1,#holdQueue do for n=1,#holdQueue do
if n==N then gc_setColor(.6,.4,.4)end if n==N then gc_setColor(.6,.4,.4)end
local bk,clr=holdQueue[n].bk,holdQueue[n].color local bk,clr=holdQueue[n].bk,holdQueue[n].color
local texture=P.skinLib[clr] local texture=skinLib[clr]
local k=min(2.3/#bk,3/#bk[1],.85) local k=min(2.3/#bk,3/#bk[1],.85)
gc_scale(k) gc_scale(k)
for i=1,#bk do for j=1,#bk[1]do for i=1,#bk do for j=1,#bk[1]do
@@ -489,11 +473,7 @@ local function drawLife(life)
if life>2 then gc_draw(IMG.lifeIcon,525,595,nil,.8)end if life>2 then gc_draw(IMG.lifeIcon,525,595,nil,.8)end
end end
end end
local function drawMission(P) local function drawMission(curMission,L)
if not P.curMission then return end
local L=P.gameEnv.mission
local cur=P.curMission
--Draw current mission --Draw current mission
setFont(35) setFont(35)
if P.gameEnv.missionkill then if P.gameEnv.missionkill then
@@ -501,12 +481,12 @@ local function drawMission(P)
else else
gc_setColor(.97,.97,.97) gc_setColor(.97,.97,.97)
end end
gc_print(missionEnum[L[cur]],85,110) gc_print(missionEnum[L[curMission]],85,110)
--Draw next mission --Draw next mission
setFont(20) setFont(20)
for i=1,3 do for i=1,3 do
local m=L[cur+i] local m=L[curMission+i]
if m then if m then
m=missionEnum[m] m=missionEnum[m]
gc_print(m,87-28*i,117) gc_print(m,87-28*i,117)
@@ -515,12 +495,12 @@ local function drawMission(P)
end end
end end
end end
local function drawStartCounter(P) local function drawStartCounter(time)
local count=179-P.frameRun time=179-time
gc_push('transform') gc_push('transform')
gc_translate(300,300) gc_translate(300,300)
local num=int(count/60)+1 local num=int(time/60)+1
local d=count%60 local d=time%60
if num==3 then if num==3 then
gc_setColor(.7,.8,.98) gc_setColor(.7,.8,.98)
if d>45 then gc_rotate((d-45)^2*.00355)end if d>45 then gc_rotate((d-45)^2*.00355)end
@@ -713,8 +693,8 @@ function draw.norm(P,repMode)
--Draw HUD --Draw HUD
P:drawNext(repMode) P:drawNext(repMode)
drawMission(P) if P.curMission then drawMission(P.curMission,ENV.mission)end
drawHold(P) if ENV.holdCount>0 then drawHold(P.holdQueue,ENV.holdCount,P.holdTime,P.skinLib)end
drawDial(499,505,P.dropSpeed) drawDial(499,505,P.dropSpeed)
if P.life>0 then drawLife(P.life)end if P.life>0 then drawLife(P.life)end
@@ -783,34 +763,34 @@ function draw.norm(P,repMode)
--Draw ghost & rotation center --Draw ghost & rotation center
local centerDisp=ENV.center and P.RS.centerDisp[C.id] local centerDisp=ENV.center and P.RS.centerDisp[C.id]
if ENV.ghost then if ENV.ghost then
drawGhost[ENV.ghostType](P,curColor,ENV.ghost) drawGhost[ENV.ghostType](P.cur.bk,P.curX,P.ghoY,ENV.ghost,P.skinLib,curColor)
if centerDisp then if centerDisp then
gc_setColor(1,1,1,ENV.center) gc_setColor(1,1,1,ENV.center)
gc_draw(P.RS.centerTex,centerX,-30*(P.ghoY+C.sc[1])+10) gc_draw(P.RS.centerTex,centerX,-30*(P.ghoY+C.sc[1])+10)
end end
elseif repMode then elseif repMode then
drawGhost.gray(P,nil,.15) drawGhost.gray(P.cur.bk,P.curX,P.ghoY,.15,nil,nil)
end end
local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0 local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
gc_translate(0,-dy) gc_translate(0,-dy)
--Draw block & rotation center --Draw block & rotation center
if ENV.block then if ENV.block then
drawBlockOutline(P,P.skinLib[curColor],trans) drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],trans)
drawBlock(P,curColor) drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
if centerDisp then if centerDisp then
gc_setColor(1,1,1,ENV.center) gc_setColor(1,1,1,ENV.center)
gc_draw(P.RS.centerTex,centerX,-30*(P.curY+C.sc[1])+10) gc_draw(P.RS.centerTex,centerX,-30*(P.curY+C.sc[1])+10)
end end
elseif repMode then elseif repMode then
drawBlockShade(P,trans*.3) drawBlockShade(P.cur.bk,P.curX,P.curY,trans*.3)
end end
gc_translate(0,dy) gc_translate(0,dy)
end end
--Draw next preview --Draw next preview
if ENV.nextPos and P.nextQueue[1]then if ENV.nextPos and P.nextQueue[1]then
drawNextPreview(P,P.nextQueue[1]) drawNextPreview(P.nextQueue[1],ENV.fieldH,P.fieldBeneath)
end end
--Draw AI's drop destination --Draw AI's drop destination
@@ -845,9 +825,9 @@ function draw.norm(P,repMode)
--Draw Frame and buffers --Draw Frame and buffers
gc_setColor(P.frameColor) gc_setColor(P.frameColor)
gc_draw(playerBoarder,-17,-12) gc_draw(playerBoarder,-17,-12)
drawBuffer(P) drawBuffer(P.atkBuffer,ENV.bufferWarn,P.atkBufferSum1,P.atkBufferSum)
drawB2Bbar(P) drawB2Bbar(P.b2b,P.b2b1)
drawLDI(P,ENV) drawLDI(ENV.easyFresh,P.lockDelay/ENV.lock,P.freshTime)
--Draw target selecting pad --Draw target selecting pad
if GAME.modeEnv.royaleMode then if GAME.modeEnv.royaleMode then
@@ -908,7 +888,7 @@ function draw.norm(P,repMode)
GAME.curMode.mesDisp(P) GAME.curMode.mesDisp(P)
end end
if P.frameRun<180 then drawStartCounter(P)end if P.frameRun<180 then drawStartCounter(P.frameRun)end
gc_pop() gc_pop()
end end
function draw.small(P) function draw.small(P)
@@ -984,12 +964,12 @@ function draw.demo(P)
drawField(P) drawField(P)
drawFXs(P) drawFXs(P)
if P.cur and P.waiting==-1 then if P.cur and P.waiting==-1 then
if ENV.ghost then drawGhost[ENV.ghostType](P,curColor,ENV.ghost)end if ENV.ghost then drawGhost[ENV.ghostType](P.cur.bk,P.curX,P.ghoY,ENV.ghost,P.skinLib,curColor)end
if ENV.block then if ENV.block then
local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0 local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
gc_translate(0,-dy) gc_translate(0,-dy)
drawBlockOutline(P,P.skinLib[curColor],P.lockDelay/ENV.lock) drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],P.lockDelay/ENV.lock)
drawBlock(P,curColor) drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
gc_translate(0,dy) gc_translate(0,dy)
end end
end end