整理并重写部分玩家绘制代码

This commit is contained in:
MrZ626
2020-09-16 17:47:35 +08:00
parent b139cfe62f
commit 045b352064

View File

@@ -496,8 +496,66 @@ local frameColor={
color.lPurple, color.lPurple,
color.lOrange, color.lOrange,
} }
local function drawPixel(y,x,id) local function drawCell(y,x,id)
gc.draw(blockSkin[id],30*x-30,600-30*y) gc.draw(blockSkin[id],30*x-30,-30*y)
end
local function drawGrid(P)
local FBN,FUP=P.fieldBeneath,P.fieldUp
gc.setLineWidth(1)
gc.setColor(1,1,1,.2)
for x=1,9 do
gc.line(30*x,-10,30*x,600)
end
for y=0,19 do
y=30*(y-int((FBN+FUP)/30))+FBN+FUP
gc.line(0,y,300,y)
end
end
local function drawField(P)
local V,F=P.visTime,P.field
local start=int((P.fieldBeneath+P.fieldUp)/30+1)
local rep=game.replaying
if P.falling==-1 then--Blocks only
for j=start,min(start+20,#F)do
for i=1,10 do
if F[j][i]>0 then
if V[j][i]>0 then
gc.setColor(1,1,1,min(V[j][i]*.05,1))
drawCell(j,i,F[j][i])
elseif rep then
gc.setColor(1,1,1,.3+.08*sin(.5*(j-i)+Timer()*4))
gc.rectangle("fill",30*i-30,-30*j,30,30)
end
end
end
end
else--With falling animation
local ENV=P.gameEnv
local dy,stepY=0,ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
local A=P.falling/ENV.fall
local h=1
for j=start,min(start+20,#F)do
while j==P.clearingRow[h]do
h=h+1
dy=dy+stepY
gc.translate(0,-stepY)
gc.setColor(1,1,1,A)
gc.rectangle("fill",0,30-30*j,300,stepY)
end
for i=1,10 do
if F[j][i]>0 then
if V[j][i]>0 then
gc.setColor(1,1,1,min(V[j][i]*.05,1))
drawCell(j,i,F[j][i])
elseif rep then
gc.setColor(1,1,1,.2)
gc.rectangle("fill",30*i-30,-30*j,30,30)
end
end
end
end
gc.translate(0,dy)
end
end end
local function drawFXs(P) local function drawFXs(P)
--LockFX --LockFX
@@ -517,14 +575,14 @@ local function drawFXs(P)
local S=P.dropFX[i] local S=P.dropFX[i]
gc.setColor(1,1,1,.6-S[5]*.6) gc.setColor(1,1,1,.6-S[5]*.6)
local w=30*S[3]*(1-S[5]*.5) local w=30*S[3]*(1-S[5]*.5)
gc.rectangle("fill",30*S[1]-30+15*S[3]-w*.5,600-30*S[2],w,30*S[4]) gc.rectangle("fill",30*S[1]-30+15*S[3]-w*.5,-30*S[2],w,30*S[4])
end end
--MoveFX --MoveFX
for i=1,#P.moveFX do for i=1,#P.moveFX do
local S=P.moveFX[i] local S=P.moveFX[i]
gc.setColor(1,1,1,.6-S[4]*.6) gc.setColor(1,1,1,.6-S[4]*.6)
drawPixel(S[3],S[2],S[1]) drawCell(S[3],S[2],S[1])
end end
--ClearFX --ClearFX
@@ -534,9 +592,59 @@ local function drawFXs(P)
local x=t<.3 and 1-(3.3333*t-1)^2 or 1 local x=t<.3 and 1-(3.3333*t-1)^2 or 1
local y=t<.2 and 5*t or 1-1.25*(t-.2) local y=t<.2 and 5*t or 1-1.25*(t-.2)
gc.setColor(1,1,1,y) gc.setColor(1,1,1,y)
gc.rectangle("fill",150-x*150,615-S[1]*30-y*15,300*x,y*30) gc.rectangle("fill",150-x*150,15-S[1]*30-y*15,300*x,y*30)
end end
end end
local function drawGhost(P,clr)
gc.setColor(1,1,1,P.gameEnv.ghost)
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
drawCell(i+P.imgY-1,j+P.curX-1,clr)
end
end end
end
local function drawBlockOutline(P,clr,trans)
SHADER.alpha:send("a",trans)
gc.setShader(SHADER.alpha)
local _=blockSkin[clr]
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
local x=30*(j+P.curX)-60-3
local y=30-30*(i+P.curY)-3
gc.draw(_,x,y)gc.draw(_,x+6,y+6)
gc.draw(_,x+6,y)gc.draw(_,x,y+6)
end
end end
gc.setShader()
end
local function drawBlock(P,clr)
gc.setColor(1,1,1)
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
drawCell(i+P.curY-1,j+P.curX-1,clr)
end
end end
end
local function drawNextPreview(P,B)
gc.setColor(1,1,1,.8)
local x=int(6-#B[1]*.5)
local y=21+ceil(P.fieldBeneath/30)
for i=1,#B do for j=1,#B[1]do
if B[i][j]then
gc.draw(puzzleMark[-1],30*(x+j-2),30*(1-y-i))
end
end end
end
local function drawHold(P,clr)
if P.holded then gc.setColor(.6,.4,.4)end
local B=P.hd.bk
for i=1,#B do for j=1,#B[1]do
if B[i][j]then
drawCell(i+1.36-#B*.5,j+2.06-#B[1]*.5,clr)
end
end end
end
local Pdraw_norm local Pdraw_norm
do--function Pdraw_norm(P) do--function Pdraw_norm(P)
local attackColor={ local attackColor={
@@ -578,76 +686,28 @@ do--function Pdraw_norm(P)
gc.translate(P.fieldOff.x,P.fieldOff.y) gc.translate(P.fieldOff.x,P.fieldOff.y)
--Fill field --Fill field
gc.setColor(0,0,0,.6)gc.rectangle("fill",0,-10,300,610) gc.setColor(0,0,0,.6)
gc.rectangle("fill",0,-10,300,610)
--Grid --Draw grid
if ENV.grid then if ENV.grid then drawGrid(P)end
gc.setLineWidth(1)
gc.setColor(1,1,1,.2)
for x=1,9 do gc.line(30*x,-10,30*x,600)end
for y=0,19 do
y=30*(y-int((FBN+FUP)/30))+FBN+FUP
gc.line(0,y,300,y)
end
end
--In-field things --In-field things
gc.push("transform") gc.push("transform")
gc.translate(0,FBN+FUP) gc.translate(0,600+FBN+FUP)
gc.setScissor(scr.x+(P.absFieldX+P.fieldOff.x)*scr.k,scr.y+(P.absFieldY+P.fieldOff.y)*scr.k,300*P.size*scr.k,610*P.size*scr.k) gc.setScissor(scr.x+(P.absFieldX+P.fieldOff.x)*scr.k,scr.y+(P.absFieldY+P.fieldOff.y)*scr.k,300*P.size*scr.k,610*P.size*scr.k)
--Draw dangerous area --Draw dangerous area
gc.setColor(1,0,0,.2) gc.setColor(1,0,0,.3)
gc.rectangle("fill",0,0,300,-FUP-FBN-10) gc.rectangle("fill",0,-600,300,-610-FUP-FBN)
--Draw field --Draw field
local V=P.visTime drawField(P)
local F=P.field
if P.falling==-1 then--Blocks only
for j=int(FBN/30+1),#F do
for i=1,10 do
if F[j][i]>0 then
if V[j][i]>0 then
gc.setColor(1,1,1,min(V[j][i]*.05,1))
drawPixel(j,i,F[j][i])
elseif game.replaying then
gc.setColor(1,1,1,.3+.08*sin(.5*(j-i)+Timer()*4))
gc.rectangle("fill",30*i-30,600-30*j,30,30)
end
end
end
end
else--With falling animation
local dy,stepY=0,ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
local A=P.falling/ENV.fall
local h,H=1,#F
for j=int(FBN/30+1),H do
while j==P.clearingRow[h]do
h=h+1
dy=dy+stepY
gc.translate(0,-stepY)
gc.setColor(1,1,1,A)
gc.rectangle("fill",0,630-30*j,300,stepY)
end
for i=1,10 do
if F[j][i]>0 then
if V[j][i]>0 then
gc.setColor(1,1,1,min(V[j][i]*.05,1))
drawPixel(j,i,F[j][i])
elseif game.replaying then
gc.setColor(1,1,1,.2)
gc.rectangle("fill",30*i-30,600-30*j,30,30)
end
end
end
end
gc.translate(0,dy)
end
--Draw spawn line --Draw spawn line
gc.setColor(1,sin(Timer())*.4+.5,0,.5) gc.setColor(1,sin(Timer())*.4+.5,0,.5)
gc.setLineWidth(4) gc.setLineWidth(4)
gc.line(0,0-FBN,300,0-FBN) gc.line(0,-600-FBN,300,-600-FBN)
--Draw FXs --Draw FXs
drawFXs(P) drawFXs(P)
@@ -656,69 +716,35 @@ do--function Pdraw_norm(P)
if P.cur and P.waiting==-1 then if P.cur and P.waiting==-1 then
local curColor=P.cur.color local curColor=P.cur.color
--Ghost --Draw ghost
if ENV.ghost then if ENV.ghost then drawGhost(P,curColor)end
gc.setColor(1,1,1,ENV.ghost)
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
drawPixel(i+P.imgY-1,j+P.curX-1,curColor)
end
end end
end
local dy=ENV.smooth and P.imgY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0 local dy=ENV.smooth and P.imgY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
gc.translate(0,-dy) gc.translate(0,-dy)
local trans=P.lockDelay/ENV.lock local trans=P.lockDelay/ENV.lock
if ENV.block then
--White Boarder(indicate lockdelay)
SHADER.alpha:send("a",trans)
gc.setShader(SHADER.alpha)
_=blockSkin[curColor]
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
local x=30*(j+P.curX)-60-3
local y=630-30*(i+P.curY)-3
gc.draw(_,x,y)gc.draw(_,x+6,y+6)
gc.draw(_,x+6,y)gc.draw(_,x,y+6)
end
end end
gc.setShader()
--Block --Draw block
gc.setColor(1,1,1) if ENV.block then
for i=1,P.r do for j=1,P.c do drawBlockOutline(P,curColor,trans)
if P.cur.bk[i][j]then drawBlock(P,curColor)
drawPixel(i+P.curY-1,j+P.curX-1,curColor)
end
end end
end end
--Rotate center --Draw rotate center
local x=30*(P.curX+P.sc[2])-15 local x=30*(P.curX+P.sc[2])-15
if ENV.center then if ENV.center then
gc.setColor(1,1,1,trans*ENV.center) gc.setColor(1,1,1,trans*ENV.center)
gc.draw(IMG.spinCenter,x,600-30*(P.curY+P.sc[1])+15,nil,nil,nil,4,4) gc.draw(IMG.spinCenter,x,-30*(P.curY+P.sc[1])+15,nil,nil,nil,4,4)
end end
gc.translate(0,dy) gc.translate(0,dy)
if ENV.center and ENV.ghost then if ENV.center and ENV.ghost then
gc.setColor(1,1,1,trans*ENV.center) gc.setColor(1,1,1,trans*ENV.center)
gc.draw(IMG.spinCenter,x,600-30*(P.imgY+P.sc[1])+15,nil,nil,nil,4,4) gc.draw(IMG.spinCenter,x,-30*(P.imgY+P.sc[1])+15,nil,nil,nil,4,4)
end end
end end
--Draw next preview --Draw next preview
if ENV.nextPos and P.next[1]then if ENV.nextPos and P.next[1]then
gc.setColor(1,1,1,.8) drawNextPreview(P,P.next[1].bk)
local B=P.next[1].bk
local x=int(6-#B[1]*.5)
local y=21+ceil(P.fieldBeneath/30)
for i=1,#B do
for j=1,#B[1]do
if B[i][j]then
gc.draw(puzzleMark[-1],30*(x+j-2),30*(21-y-i))
end
end
end
end end
gc.setScissor() gc.setScissor()
@@ -727,24 +753,9 @@ do--function Pdraw_norm(P)
gc.setLineWidth(2) gc.setLineWidth(2)
gc.setColor(P.frameColor) gc.setColor(P.frameColor)
gc.rectangle("line",-1,-11,302,612)--Boarder gc.rectangle("line",-1,-11,302,612)--Boarder
gc.rectangle("line",301,0,15,601)--AtkBuffer boarder gc.rectangle("line",301,-3,15,604)--AtkBuffer boarder
gc.rectangle("line",-16,-3,15,604)--B2b bar boarder gc.rectangle("line",-16,-3,15,604)--B2b bar boarder
--LockDelay indicator
if ENV.easyFresh then
gc.setColor(1,1,1)
else
gc.setColor(1,.26,.26)
end
if P.lockDelay>=0 then
gc.rectangle("fill",0,602,300*P.lockDelay/ENV.lock,6)--Lock delay indicator
end
_=3
for i=1,min(ENV.freshLimit-P.freshTime,15)do
gc.rectangle("fill",_,615,14,5)
_=_+20
end
--Buffer line --Buffer line
local h=0 local h=0
for i=1,#P.atkBuffer do for i=1,#P.atkBuffer do
@@ -759,20 +770,20 @@ do--function Pdraw_norm(P)
if A.countdown>0 then if A.countdown>0 then
--Timing --Timing
gc.setColor(attackColor[A.lv][1]) gc.setColor(attackColor[A.lv][1])
gc.rectangle("fill",303,599-h,11,-bar+3) gc.rectangle("fill",303,599-h,11,-bar)
gc.setColor(attackColor[A.lv][2]) gc.setColor(attackColor[A.lv][2])
gc.rectangle("fill",303,599-h+(-bar+3),11,-(-bar+3)*(1-A.countdown/A.cd0)) gc.rectangle("fill",303,599-h-bar,11,bar*(1-A.countdown/A.cd0))
else else
--Warning --Warning
local t=math.sin((Timer()-i)*30)*.5+.5 local t=math.sin((Timer()-i)*30)*.5+.5
local c1,c2=attackColor[A.lv][1],attackColor[A.lv][2] local c1,c2=attackColor[A.lv][1],attackColor[A.lv][2]
gc.setColor(c1[1]*t+c2[1]*(1-t),c1[2]*t+c2[2]*(1-t),c1[3]*t+c2[3]*(1-t)) gc.setColor(c1[1]*t+c2[1]*(1-t),c1[2]*t+c2[2]*(1-t),c1[3]*t+c2[3]*(1-t))
gc.rectangle("fill",303,599-h,11,-bar+3) gc.rectangle("fill",303,599-h,11,-bar)
end end
else else
gc.setColor(attackColor[A.lv][1]) gc.setColor(attackColor[A.lv][1])
bar=bar*(20-A.time)*.05 bar=bar*(20-A.time)*.05
gc.rectangle("fill",303,599-h,11,-bar+2) gc.rectangle("fill",303,599-h,11,-bar)
--Disappear --Disappear
end end
h=h+bar h=h+bar
@@ -789,20 +800,32 @@ do--function Pdraw_norm(P)
gc.rectangle("fill",-15,b<40 and 578.5 or 98.5,13,3) gc.rectangle("fill",-15,b<40 and 578.5 or 98.5,13,3)
end end
--LockDelay indicator
if ENV.easyFresh then
gc.setColor(1,1,1)
else
gc.setColor(1,.26,.26)
end
if P.lockDelay>=0 then
gc.rectangle("fill",0,602,300*P.lockDelay/ENV.lock,6)--Lock delay indicator
end
_=3
for i=1,min(ENV.freshLimit-P.freshTime,15)do
gc.rectangle("fill",_,615,14,5)
_=_+20
end
--Draw Hold --Draw Hold
if ENV.hold then if ENV.hold then
gc.setColor(0,0,0,.4)gc.rectangle("fill",-140,36,124,80) gc.push("transform")
gc.setColor(1,1,1)gc.rectangle("line",-140,36,124,80) gc.translate(-140,116)--TODO: adjust needed
mText(drawableText.hold,-78,-15) gc.setColor(0,0,0,.4)gc.rectangle("fill",0,-80,124,80)
if P.hd then gc.setColor(1,1,1)gc.rectangle("line",0,-80,124,80)
if P.holded then gc.setColor(.6,.5,.5)end mText(drawableText.hold,62,-131)
local B=P.hd.bk if P.hd then
for i=1,#B do for j=1,#B[1]do drawHold(P,P.hd.color)
if B[i][j]then end
drawPixel(i+17.5-#B*.5,j-2.6-#B[1]*.5,P.hd.color) gc.pop()
end
end end
end
end end
--Draw Next(s) --Draw Next(s)
@@ -816,7 +839,7 @@ do--function Pdraw_norm(P)
local b,c=P.next[N].bk,P.next[N].color local b,c=P.next[N].bk,P.next[N].color
for i=1,#b do for j=1,#b[1] do for i=1,#b do for j=1,#b[1] do
if b[i][j]then if b[i][j]then
drawPixel(i+20-2.4*N-#b*.5,j+12.6-#b[1]*.5,c) drawCell(i-2.4*N-#b*.5,j+12.6-#b[1]*.5,c)
end end
end end end end
N=N+1 N=N+1
@@ -917,14 +940,18 @@ local function Pdraw_small(P)
if P.alive then if P.alive then
gc.setLineWidth(2) gc.setLineWidth(2)
gc.setColor(P.frameColor) gc.setColor(P.frameColor)
gc.rectangle("line",1,1,58,118) gc.rectangle("line",0,0,60,120)
end end
--Draw badge
if modeEnv.royaleMode then if modeEnv.royaleMode then
gc.setColor(1,1,1) gc.setColor(1,1,1)
for i=1,P.strength do for i=1,P.strength do
gc.draw(IMG.badgeIcon,12*i-7,4,nil,.5) gc.draw(IMG.badgeIcon,12*i-7,4,nil,.5)
end end
end end
--Draw result
if P.result then if P.result then
gc.setColor(1,1,1,min(P.endCounter,60)*.01) gc.setColor(1,1,1,min(P.endCounter,60)*.01)
setFont(17)mStr(P.result,32,47) setFont(17)mStr(P.result,32,47)
@@ -961,60 +988,63 @@ local function Pdraw_demo(P)
gc.setColor(1,1,1) gc.setColor(1,1,1)
gc.rectangle("line",-1,-1,302,602) gc.rectangle("line",-1,-1,302,602)
if P.falling==-1 then gc.push("transform")
--Field block only gc.translate(0,600)
for j=int(P.fieldBeneath/30+1),#P.field do if P.falling==-1 then
for i=1,10 do --Field block only
if P.field[j][i]>0 then for j=int(P.fieldBeneath/30+1),#P.field do
gc.setColor(1,1,1,min(P.visTime[j][i]*.05,1)) for i=1,10 do
drawPixel(j,i,P.field[j][i]) if P.field[j][i]>0 then
gc.setColor(1,1,1,min(P.visTime[j][i]*.05,1))
drawCell(j,i,P.field[j][i])
end
end end
end end
end else
else --Field with falling animation
--Field with falling animation local dy,stepY=0,ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30
local dy,stepY=0,ENV.smooth and(P.falling/(ENV.fall+1))^2.5*30 or 30 local A=P.falling/ENV.fall
local A=P.falling/ENV.fall local h,H=1,#P.field
local h,H=1,#P.field for j=int(P.fieldBeneath/30+1),H do
for j=int(P.fieldBeneath/30+1),H do while j==P.clearingRow[h]do
while j==P.clearingRow[h]do h=h+1
h=h+1 dy=dy+stepY
dy=dy+stepY gc.translate(0,-stepY)
gc.translate(0,-stepY) gc.setColor(1,1,1,A)
gc.setColor(1,1,1,A) gc.rectangle("fill",0,630-30*j,300,stepY)
gc.rectangle("fill",0,630-30*j,300,stepY) end
end for i=1,10 do
for i=1,10 do if P.field[j][i]>0 then
if P.field[j][i]>0 then gc.setColor(1,1,1,min(P.visTime[j][i]*.05,1))
gc.setColor(1,1,1,min(P.visTime[j][i]*.05,1)) drawCell(j,i,P.field[j][i])
drawPixel(j,i,P.field[j][i]) end
end end
end end
gc.translate(0,dy)
end end
gc.translate(0,dy)
end
drawFXs(P) drawFXs(P)
if P.cur and P.waiting==-1 then if P.cur and P.waiting==-1 then
--Draw ghost --Draw ghost
if ENV.ghost then if ENV.ghost then
gc.setColor(1,1,1,ENV.ghost) gc.setColor(1,1,1,ENV.ghost)
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
drawCell(i+P.imgY-1,j+P.curX-1,curColor)
end
end end
end
--Draw block
gc.setColor(1,1,1)
for i=1,P.r do for j=1,P.c do for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then if P.cur.bk[i][j]then
drawPixel(i+P.imgY-1,j+P.curX-1,curColor) drawCell(i+P.curY-1,j+P.curX-1,curColor)
end end
end end end end
end end
gc.pop()
--Draw block
gc.setColor(1,1,1)
for i=1,P.r do for j=1,P.c do
if P.cur.bk[i][j]then
drawPixel(i+P.curY-1,j+P.curX-1,curColor)
end
end end
end
--Draw hold --Draw hold
local blockImg=TEXTURE.miniBlock local blockImg=TEXTURE.miniBlock
@@ -1186,6 +1216,7 @@ local function applyGameEnv(P)--Finish gameEnv processing
if ENV.moveFX==0 then ENV.moveFX=nil end if ENV.moveFX==0 then ENV.moveFX=nil end
if ENV.clearFX==0 then ENV.clearFX=nil end if ENV.clearFX==0 then ENV.clearFX=nil end
if ENV.shakeFX==0 then ENV.shakeFX=nil end if ENV.shakeFX==0 then ENV.shakeFX=nil end
if ENV.ghost==0 then ENV.ghost=nil end if ENV.ghost==0 then ENV.ghost=nil end
if ENV.center==0 then ENV.center=nil end if ENV.center==0 then ENV.center=nil end
end end
@@ -1361,7 +1392,7 @@ function player.createLockFX(P)
for i=1,P.r do for i=1,P.r do
local y=P.curY+i-1 local y=P.curY+i-1
if without(P.clearedRow,y)then if without(P.clearedRow,y)then
y=600-30*y y=-30*y
for j=1,P.c do for j=1,P.c do
if BK[i][j]then if BK[i][j]then
ins(P.lockFX,{30*(P.curX+j-2),y,0,t}) ins(P.lockFX,{30*(P.curX+j-2),y,0,t})