精简代码

This commit is contained in:
MrZ626
2020-10-23 00:01:44 +08:00
parent 3cb3cf5fac
commit aa48fbfb33

View File

@@ -445,30 +445,30 @@ local function drawField(P)
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 stepY=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+21,#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)
gc.push("transform")
for j=start,min(start+21,#F)do
while j==P.clearingRow[h]do
h=h+1
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
end
gc.translate(0,dy)
gc.pop()
end
end
local function drawFXs(P)
@@ -955,98 +955,52 @@ local function Pdraw_demo(P)
--Camera
gc.push("transform")
gc.translate(P.x,P.y)gc.scale(P.size)gc.translate(P.fieldOff.x,P.fieldOff.y)
gc.translate(P.x,P.y)gc.scale(P.size)
gc.push("transform")
gc.translate(P.fieldOff.x,P.fieldOff.y)
--Frame
gc.setColor(.1,.1,.1,.8)
gc.rectangle("fill",0,0,300,600)
gc.setLineWidth(2)
gc.setColor(1,1,1)
gc.rectangle("line",-1,-1,302,602)
gc.push("transform")
gc.translate(0,600)
if P.falling==-1 then
--Field block only
for j=int(P.fieldBeneath/30+1),#P.field do
for i=1,10 do
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
else
--Field 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,#P.field
for j=int(P.fieldBeneath/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 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
gc.translate(0,dy)
end
drawFXs(P)
if P.cur and P.waiting==-1 then
--Draw ghost
if ENV.ghost then
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
--Frame
gc.setColor(0,0,0,.6)
gc.rectangle("fill",0,0,300,600)
gc.setLineWidth(2)
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,curColor)
gc.rectangle("line",-1,-1,302,602)
gc.push("transform")
gc.translate(0,600)
drawField(P)
drawFXs(P)
if P.cur and P.waiting==-1 then
if ENV.ghost then drawGhost(P,curColor)end
if ENV.block then
drawBlockOutline(P,curColor,P.lockDelay/ENV.lock)
drawBlock(P,curColor)
end
end
end end
end
gc.pop()
gc.pop()
--Draw hold
local blockImg=TEXTURE.miniBlock
if P.hd then
local id=P.hd.id
_=P.color[id]
gc.setColor(_[1],_[2],_[3],.3)
_=blockImg[id]
gc.draw(_,15,30,nil,16,nil,0,_:getHeight()*.5)
end
--Draw hold
local blockImg=TEXTURE.miniBlock
if P.hd then
local id=P.hd.id
_=P.color[id]
gc.setColor(_[1],_[2],_[3],.3)
_=blockImg[id]
gc.draw(_,15,30,nil,16,nil,0,_:getHeight()*.5)
end
--Draw next
local N=1
while N<=ENV.next and P.next[N]do
local id=P.next[N].id
_=P.color[id]
gc.setColor(_[1],_[2],_[3],.3)
_=blockImg[id]
gc.draw(_,285,40*N-10,nil,16,nil,_:getWidth(),_:getHeight()*.5)
N=N+1
end
gc.setColor(1,1,1)
gc.translate(-P.fieldOff.x,-P.fieldOff.y)
TEXT.draw(P.bonus)
--Draw next
local N=1
while N<=ENV.next and P.next[N]do
local id=P.next[N].id
_=P.color[id]
gc.setColor(_[1],_[2],_[3],.3)
_=blockImg[id]
gc.draw(_,285,40*N-10,nil,16,nil,_:getWidth(),_:getHeight()*.5)
N=N+1
end
gc.pop()
TEXT.draw(P.bonus)
gc.pop()
end
function player.drawTargetLine(P,r)