整理代码,从Player:drop中抽离出几个过程
This commit is contained in:
@@ -25,6 +25,13 @@ end
|
|||||||
function Player:showTextF(text,dx,dy,font,style,spd,stop)
|
function Player:showTextF(text,dx,dy,font,style,spd,stop)
|
||||||
ins(self.bonus,TEXT.getText(text,150+dx,300+dy,font,style,spd,stop))
|
ins(self.bonus,TEXT.getText(text,150+dx,300+dy,font,style,spd,stop))
|
||||||
end
|
end
|
||||||
|
function Player:popScore(score,x,y)
|
||||||
|
self:showText(
|
||||||
|
score,x,y,
|
||||||
|
40-600/(score+20),
|
||||||
|
'score',2
|
||||||
|
)
|
||||||
|
end
|
||||||
function Player:createLockFX()
|
function Player:createLockFX()
|
||||||
local CB=self.cur.bk
|
local CB=self.cur.bk
|
||||||
local t=12-self.gameEnv.lockFX*2
|
local t=12-self.gameEnv.lockFX*2
|
||||||
@@ -316,6 +323,9 @@ end
|
|||||||
function Player:getCenterX()
|
function Player:getCenterX()
|
||||||
return self.curX+self.cur.sc[2]-5.5
|
return self.curX+self.cur.sc[2]-5.5
|
||||||
end
|
end
|
||||||
|
function Player:getCenterY()
|
||||||
|
return self.curY-self.cur.sc[1]
|
||||||
|
end
|
||||||
function Player:solid(x,y)
|
function Player:solid(x,y)
|
||||||
if x<1 or x>10 or y<1 then return true end
|
if x<1 or x>10 or y<1 then return true end
|
||||||
if y>#self.field then return false end
|
if y>#self.field then return false end
|
||||||
@@ -538,6 +548,80 @@ function Player:lock()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Player:checkClear(field,start,height,CB,CX)
|
||||||
|
local cc=0
|
||||||
|
if self.gameEnv.fillClear then
|
||||||
|
for i=1,height do
|
||||||
|
local h=start+i-2
|
||||||
|
|
||||||
|
--Bomb trigger (optional, must with CB)
|
||||||
|
if CB and h>0 and field[h]and self.clearedRow[cc]~=h then
|
||||||
|
for x=1,#CB[1]do
|
||||||
|
if CB[i][x]and field[h][CX+x-1]==19 then
|
||||||
|
cc=cc+1
|
||||||
|
self.clearingRow[cc]=h-cc+1
|
||||||
|
self.clearedRow[cc]=h
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
h=h+1
|
||||||
|
--Row filled
|
||||||
|
for x=1,10 do
|
||||||
|
if field[h][x]<=0 then
|
||||||
|
goto CONTINUE_notFull
|
||||||
|
end
|
||||||
|
end
|
||||||
|
cc=cc+1
|
||||||
|
ins(self.clearingRow,h-cc+1)
|
||||||
|
ins(self.clearedRow,h)
|
||||||
|
::CONTINUE_notFull::
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return cc
|
||||||
|
end
|
||||||
|
function Player:roofCheck()
|
||||||
|
local CB=self.cur.bk
|
||||||
|
for x=1,#CB[1]do
|
||||||
|
local y=#CB
|
||||||
|
|
||||||
|
--Find the highest y of blocks' x-th column
|
||||||
|
while not CB[y][x]do y=y-1 end
|
||||||
|
|
||||||
|
local testX=self.curX+x-1--Optimize
|
||||||
|
|
||||||
|
--Test the whole column of field to find roof
|
||||||
|
for testY=self.curY+y,#self.field do
|
||||||
|
if self:solid(testX,testY)then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
function Player:removeTopClearingFX()
|
||||||
|
for i=#self.clearingRow,1,-1 do
|
||||||
|
if self.clearingRow[i]>#self.field then
|
||||||
|
rem(self.clearingRow)
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function Player:checkMission(piece,mission)
|
||||||
|
if mission<5 then
|
||||||
|
return piece.row==mission and not piece.spin
|
||||||
|
elseif mission<9 then
|
||||||
|
return piece.row==mission-4 and piece.spin
|
||||||
|
elseif mission==9 then
|
||||||
|
return piece.pc
|
||||||
|
elseif mission<90 then
|
||||||
|
return piece.row==mission%10 and piece.name==int(mission/10)and piece.spin
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local spawnSFX_name={}for i=1,7 do spawnSFX_name[i]='spawn_'..i end
|
local spawnSFX_name={}for i=1,7 do spawnSFX_name[i]='spawn_'..i end
|
||||||
function Player:resetBlock()--Reset Block's position and execute I*S
|
function Player:resetBlock()--Reset Block's position and execute I*S
|
||||||
local B=self.cur.bk
|
local B=self.cur.bk
|
||||||
@@ -1006,46 +1090,16 @@ do--Player.drop(self)--Place piece
|
|||||||
self:lock()
|
self:lock()
|
||||||
|
|
||||||
--Clear list of cleared-rows
|
--Clear list of cleared-rows
|
||||||
if self.clearedRow[1]then self.clearedRow={}end
|
if self.clearedRow[1]then TABLE.cut(self.clearedRow)end
|
||||||
|
|
||||||
--Check line clear
|
--Check line clear
|
||||||
if ENV.fillClear then
|
cc=cc+self:checkClear(self.field,CY,#CB,CB,CX)
|
||||||
for i=1,#CB do
|
|
||||||
local h=CY+i-2
|
|
||||||
|
|
||||||
--Bomb trigger
|
|
||||||
if h>0 and self.field[h]and self.clearedRow[cc]~=h then
|
|
||||||
for x=1,#CB[1]do
|
|
||||||
if CB[i][x]and self.field[h][CX+x-1]==19 then
|
|
||||||
cc=cc+1
|
|
||||||
self.clearingRow[cc]=h-cc+1
|
|
||||||
self.clearedRow[cc]=h
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
h=h+1
|
|
||||||
--Row filled
|
|
||||||
for x=1,10 do
|
|
||||||
if self.field[h][x]<=0 then
|
|
||||||
goto CONTINUE_notFull
|
|
||||||
end
|
|
||||||
end
|
|
||||||
cc=cc+1
|
|
||||||
self.clearingRow[cc]=h-cc+1
|
|
||||||
self.clearedRow[cc]=h
|
|
||||||
::CONTINUE_notFull::
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Create clearing FX
|
--Create clearing FX
|
||||||
if cc>0 then
|
for i=1,cc do
|
||||||
for i=1,cc do
|
local y=self.clearedRow[i]
|
||||||
local y=self.clearedRow[i]
|
if ENV.clearFX then self:createClearingFX(y,7-ENV.clearFX)end
|
||||||
if ENV.clearFX then self:createClearingFX(y,7-ENV.clearFX)end
|
if ENV.splashFX then self:createSplashFX(y)end
|
||||||
if ENV.splashFX then self:createSplashFX(y)end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Create locking FX
|
--Create locking FX
|
||||||
@@ -1075,28 +1129,7 @@ do--Player.drop(self)--Place piece
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Finesse: roof check
|
--Finesse: roof check
|
||||||
local finesse
|
local finesse=CY>ENV.fieldH-2 or self:roofCheck()
|
||||||
if CY>ENV.fieldH-2 then
|
|
||||||
finesse=true
|
|
||||||
else
|
|
||||||
for x=1,#CB[1]do
|
|
||||||
local y=#CB
|
|
||||||
|
|
||||||
--Find the highest y of blocks' x-th column
|
|
||||||
while not CB[y][x]do y=y-1 end
|
|
||||||
|
|
||||||
local testX=CX+x-1--Optimize
|
|
||||||
|
|
||||||
--Test the whole column of field to find roof
|
|
||||||
for testY=CY+y,#self.field do
|
|
||||||
if self:solid(testX,testY)then
|
|
||||||
finesse=true
|
|
||||||
goto BERAK_roofFound
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
::BERAK_roofFound::
|
|
||||||
end
|
|
||||||
|
|
||||||
--Remove rows need to be cleared
|
--Remove rows need to be cleared
|
||||||
if cc>0 then
|
if cc>0 then
|
||||||
@@ -1112,13 +1145,7 @@ do--Player.drop(self)--Place piece
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Cancel top clearing FX
|
--Cancel top clearing FX
|
||||||
for i=#self.clearingRow,1,-1 do
|
self:removeTopClearingFX()
|
||||||
if self.clearingRow[i]>#self.field then
|
|
||||||
rem(self.clearingRow)
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if self.clearingRow[1]then
|
if self.clearingRow[1]then
|
||||||
self.falling=ENV.fall
|
self.falling=ENV.fall
|
||||||
else
|
else
|
||||||
@@ -1408,13 +1435,10 @@ do--Player.drop(self)--Place piece
|
|||||||
|
|
||||||
cscore=int(cscore)
|
cscore=int(cscore)
|
||||||
if ENV.score then
|
if ENV.score then
|
||||||
self:showText(
|
self:popScore(
|
||||||
cscore,
|
cscore,
|
||||||
(self.curX+C.sc[2]-5.5)*30,
|
self:getCenterX()*30,
|
||||||
(10-self.curY-C.sc[1])*30+self.fieldBeneath+self.fieldUp,
|
(10-self:getCenterY())*30+self.fieldBeneath+self.fieldUp
|
||||||
40-600/(cscore+20),
|
|
||||||
'score',
|
|
||||||
2
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1425,26 +1449,7 @@ do--Player.drop(self)--Place piece
|
|||||||
|
|
||||||
--Check clearing task
|
--Check clearing task
|
||||||
if cc>0 and self.curMission then
|
if cc>0 and self.curMission then
|
||||||
local t=ENV.mission[self.curMission]
|
if self:checkMission(piece,ENV.mission[self.curMission])then
|
||||||
local success
|
|
||||||
if t<5 then
|
|
||||||
if piece.row==t and not piece.spin then
|
|
||||||
success=true
|
|
||||||
end
|
|
||||||
elseif t<9 then
|
|
||||||
if piece.row==t-4 and piece.spin then
|
|
||||||
success=true
|
|
||||||
end
|
|
||||||
elseif t==9 then
|
|
||||||
if piece.pc then
|
|
||||||
success=true
|
|
||||||
end
|
|
||||||
elseif t<90 then
|
|
||||||
if piece.row==t%10 and piece.name==int(t/10)and piece.spin then
|
|
||||||
success=true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if success then
|
|
||||||
self.curMission=self.curMission+1
|
self.curMission=self.curMission+1
|
||||||
SFX.play('reach')
|
SFX.play('reach')
|
||||||
if self.curMission>#ENV.mission then
|
if self.curMission>#ENV.mission then
|
||||||
@@ -1462,11 +1467,11 @@ do--Player.drop(self)--Place piece
|
|||||||
if cc==0 and #self.field>ENV.heightLimit then self:lose()end
|
if cc==0 and #self.field>ENV.heightLimit then self:lose()end
|
||||||
|
|
||||||
--Update stat
|
--Update stat
|
||||||
Stat.score=Stat.score+cscore
|
|
||||||
Stat.piece=Stat.piece+1
|
Stat.piece=Stat.piece+1
|
||||||
Stat.row=Stat.row+cc
|
Stat.row=Stat.row+cc
|
||||||
Stat.maxFinesseCombo=max(Stat.maxFinesseCombo,self.finesseCombo)
|
Stat.maxFinesseCombo=max(Stat.maxFinesseCombo,self.finesseCombo)
|
||||||
Stat.maxCombo=max(Stat.maxCombo,self.combo)
|
Stat.maxCombo=max(Stat.maxCombo,self.combo)
|
||||||
|
Stat.score=Stat.score+cscore
|
||||||
if atk>0 then
|
if atk>0 then
|
||||||
Stat.atk=Stat.atk+atk
|
Stat.atk=Stat.atk+atk
|
||||||
if send>0 then
|
if send>0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user