代码整理

This commit is contained in:
MrZ626
2020-09-03 18:10:27 +08:00
parent c82f04e115
commit 4c94952052
2 changed files with 850 additions and 844 deletions

View File

@@ -6,7 +6,8 @@ local ins,rem=table.insert,table.remove
local format=string.format local format=string.format
local scr=scr local scr=scr
local setFont=setFont local setFont=setFont
--------------------------<GameData>--------------------------
--------------------------<Data>--------------------------
local gameEnv0={ local gameEnv0={
noTele=false, noTele=false,
das=10,arr=2, das=10,arr=2,
@@ -46,48 +47,8 @@ local gameEnv0={
bg="none",bgm="race" bg="none",bgm="race"
} }
local b2bPoint={50,100,180,300}
local b2bATK={3,5,8,10}
local clearSCR={80,200,400}
local spinSCR={--[blockName][row]
{200,750,1300},--Z
{200,750,1300},--S
{220,700,1300},--L
{220,700,1300},--J
{250,800,1400},--T
{260,900,1700},--O
{300,1200,1700},--I
{220,800,2000,3000},--Else
}
--B2BMUL:1.2/2.0
--Techrash:1K;MUL:1.3/1.8
--Mini*=.6
local reAtk={0,0,1,1,1,2,2,3,3}
local reDef={0,1,1,2,3,3,4,4,5}
local scs=require("parts/spinCenters") local scs=require("parts/spinCenters")
local kickList=require("parts/kickList") local kickList=require("parts/kickList")
local finesseList={
[1]={
{1,2,1,0,1,2,2,1},
{2,2,2,1,1,2,3,2,2},
},--Z
[3]={
{1,2,1,0,1,2,2,1},
{2,2,3,2,1,2,3,3,2},
{3,4,3,2,3,4,4,3},
{2,3,2,1,2,3,3,2,2},
},--L
[6]={
{1,2,2,1,0,1,2,2,1},
},--O
[7]={
{1,2,1,0,1,2,1},
{2,2,2,2,1,1,2,2,2,2},
},--I
}
finesseList[1][3],finesseList[1][4],finesseList[7][3],finesseList[7][4]=finesseList[1][1],finesseList[1][2],finesseList[7][1],finesseList[7][2]--"2-phase" SZI
finesseList[2]=finesseList[1]--S=Z
finesseList[4],finesseList[5]=finesseList[3],finesseList[3]--J=L=T
local CCblockID={6,5,4,3,2,1,0} local CCblockID={6,5,4,3,2,1,0}
local freshPrepare={ local freshPrepare={
none=NULL, none=NULL,
@@ -193,12 +154,7 @@ local freshMethod={
P:lose() P:lose()
end, end,
} }
local spinName={"zspin","sspin","jspin","lspin","tspin","ospin","ispin","zspin","sspin","pspin","qspin","fspin","espin","tspin","uspin","vspin","wspin","xspin","jspin","lspin","rspin","yspin","hspin","nspin","ispin"} --------------------------</Data>--------------------------
local clearName={"single","double","triple","techrash","pentcrash"}
local spin_n={[0]="spin_0","spin_1","spin_2","spin_3","spin_3"}
local clear_n={"clear_1","clear_2","clear_3","clear_4","clear_4"}
local ren_n={}for i=1,11 do ren_n[i]="ren_"..i end
--------------------------</GameData>--------------------------
--------------------------<LIB>-------------------------- --------------------------<LIB>--------------------------
local player={}--Player object local player={}--Player object
@@ -221,9 +177,9 @@ local function updateLine(P,dt)
end end
end end
end end
bf=P.fieldBeneath local bn=P.fieldBeneath
if bf>0 then if bn>0 then
P.fieldBeneath=max(bf-P.gameEnv.pushSpeed,0) P.fieldBeneath=max(bn-P.gameEnv.pushSpeed,0)
end end
end end
local function updateFXs(P,dt) local function updateFXs(P,dt)
@@ -523,32 +479,9 @@ local frameColor={
color.lPurple, color.lPurple,
color.lOrange, color.lOrange,
} }
local attackColor={
{color.dGrey,color.white},
{color.grey,color.white},
{color.lPurple,color.white},
{color.lRed,color.white},
{color.dGreen,color.cyan},
}
local RCPB={10,33,200,33,105,5,105,60}
local function drawPixel(y,x,id) local function drawPixel(y,x,id)
gc.draw(blockSkin[id],30*x-30,600-30*y) gc.draw(blockSkin[id],30*x-30,600-30*y)
end end
local function drawDial(x,y,speed)
gc.setColor(1,1,1)
mStr(int(speed),x,y-18)
gc.setLineWidth(4)
gc.setColor(1,1,1,.4)
gc.circle("line",x,y,30,10)
gc.setLineWidth(2)
gc.setColor(1,1,1,.6)
gc.circle("line",x,y,30,10)
gc.setColor(1,1,1,.8)
gc.draw(IMG.dialNeedle,x,y,2.094+(speed<=175 and .02094*speed or 4.712-52.36/(speed-125)),nil,nil,5,4)
end
local function drawFXs(P) local function drawFXs(P)
--LockFX --LockFX
for i=1,#P.lockFX do for i=1,#P.lockFX do
@@ -587,7 +520,31 @@ local function drawFXs(P)
gc.rectangle("fill",150-x*150,615-S[1]*30-y*15,300*x,y*30) gc.rectangle("fill",150-x*150,615-S[1]*30-y*15,300*x,y*30)
end end
end end
local function Pdraw_norm(P) do--local function Pdraw_norm(P)
local attackColor={
{color.dGrey,color.white},
{color.grey,color.white},
{color.lPurple,color.white},
{color.lRed,color.white},
{color.dGreen,color.cyan},
}
local RCPB={10,33,200,33,105,5,105,60}
local function drawDial(x,y,speed)
gc.setColor(1,1,1)
mStr(int(speed),x,y-18)
gc.setLineWidth(4)
gc.setColor(1,1,1,.4)
gc.circle("line",x,y,30,10)
gc.setLineWidth(2)
gc.setColor(1,1,1,.6)
gc.circle("line",x,y,30,10)
gc.setColor(1,1,1,.8)
gc.draw(IMG.dialNeedle,x,y,2.094+(speed<=175 and .02094*speed or 4.712-52.36/(speed-125)),nil,nil,5,4)
end
local function Pdraw_norm(P)
local _ local _
local ENV=P.gameEnv local ENV=P.gameEnv
gc.push("transform") gc.push("transform")
@@ -878,6 +835,7 @@ local function Pdraw_norm(P)
gc.pop() gc.pop()
end end
gc.pop() gc.pop()
end
end end
local function Pdraw_small(P) local function Pdraw_small(P)
--Draw content --Draw content
@@ -1028,6 +986,31 @@ end
--------------------------</Paint>-------------------------- --------------------------</Paint>--------------------------
--------------------------<Lib Func>-------------------------- --------------------------<Lib Func>--------------------------
local function without(L,e)
for i=1,#L do
if L[i]==e then return end
end
return true
end
local function getNewStatTable()
local T={
time=0,score=0,
key=0,rotate=0,hold=0,
extraPiece=0,extraRate=0,
piece=0,row=0,dig=0,
atk=0,digatk=0,
send=0,recv=0,pend=0,off=0,
clear={},clears={},spin={},spins={},
pc=0,hpc=0,b2b=0,b3b=0,
}
for i=1,25 do
T.clear[i]={0,0,0,0,0}
T.spin[i]={0,0,0,0,0}
T.clears[i]=0
T.spins[i]=0
end
return T
end
local function pressKey(P,i) local function pressKey(P,i)
P.keyPressing[i]=true P.keyPressing[i]=true
P.act[i](P) P.act[i](P)
@@ -1064,129 +1047,6 @@ local function releaseKey_Rec(P,i)
end end
P.keyPressing[i]=false P.keyPressing[i]=false
end end
local function without(L,e)
for i=1,#L do
if L[i]==e then return end
end
return true
end
local function getNewStatTable()
local T={
time=0,score=0,
key=0,rotate=0,hold=0,
extraPiece=0,extraRate=0,
piece=0,row=0,dig=0,
atk=0,digatk=0,
send=0,recv=0,pend=0,off=0,
clear={},clears={},spin={},spins={},
pc=0,hpc=0,b2b=0,b3b=0,
}
for i=1,25 do
T.clear[i]={0,0,0,0,0}
T.spin[i]={0,0,0,0,0}
T.clears[i]=0
T.spins[i]=0
end
return T
end
local function newEmptyPlayer(id,x,y,size)
local P={id=id}
players[id]=P
players.alive[id]=P
--Inherit functions of player class
for k,v in next,player do P[k]=v end
if P.id==1 and game.recording then
P.pressKey=pressKey_Rec
P.releaseKey=releaseKey_Rec
else
P.pressKey=pressKey
P.releaseKey=releaseKey
end
P.update=Pupdate_alive
P.fieldOff={x=0,y=0,vx=0,vy=0}--For shake FX
P.x,P.y,P.size=x,y,size or 1
P.frameColor=frameColor[0]
P.small=P.size<.1--If draw in small mode
if P.small then
P.centerX,P.centerY=P.x+300*P.size,P.y+600*P.size
P.canvas=love.graphics.newCanvas(60,120)
P.frameWait=rnd(30,120)
P.draw=Pdraw_small
else
P.keyRec=true--If calculate keySpeed
P.centerX,P.centerY=P.x+300*P.size,P.y+370*P.size
P.absFieldX=P.x+150*P.size
P.absFieldY=P.y+60*P.size
P.draw=Pdraw_norm
P.bonus={}--Text objects
end
P.randGen=mt.newRandomGenerator(game.seed)
P.small=false
P.alive=true
P.control=false
P.timing=false
P.stat=getNewStatTable()
P.modeData={point=0,event=0,counter=0}--Data use by mode
P.keyTime={}P.keySpeed=0
P.dropTime={}P.dropSpeed=0
for i=1,10 do P.keyTime[i]=-1e5 end
for i=1,10 do P.dropTime[i]=-1e5 end
P.field,P.visTime={},{}
P.atkBuffer={sum=0}
--Royale-related
P.badge,P.strength=0,0
P.atkMode,P.swappingAtkMode=1,20
P.atker,P.atking,P.lastRecv={}
P.dropDelay,P.lockDelay=0,0
P.color={}
P.showTime=nil
P.keepVisible=true
--P.cur={bk=matrix[2], id=shapeID, color=colorID, name=nameID}
--P.sc,P.dir={0,0},0--SpinCenterCoord, direction
--P.r,P.c=0,0--row, col
--P.hd={...},same as P.cur
-- P.curX,P.curY,P.imgY,P.minY=0,0,0,0--x,y,ghostY
P.holded=false
P.next={}
P.freshTime=0
P.spinLast,P.lastClear=false,nil
P.spinSeq=0--For Ospin, each digit mean a spin
P.ctrlCount=0--Key press time, for finesse check
P.pieceCount=0--Count pieces from next, for drawing bagline
P.human=false
P.RS=kickList.TRS
-- P.newNext=nil--Call prepareSequence()to get a function to get new next
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
P.movDir,P.moving,P.downing=0,0,0--Last move key,DAS charging,downDAS charging
P.waiting,P.falling=-1,-1
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
P.combo,P.b2b=0,0
P.garbageBeneath=0
P.fieldBeneath=0
P.score1,P.b2b1=0,0
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
P.tasks={}--Tasks
P.bonus={}--Texts
P.endCounter=0--Used after gameover
P.result=nil--String:"WIN"/"K.O."
return P
end
local function loadGameEnv(P)--Load gameEnv local function loadGameEnv(P)--Load gameEnv
P.gameEnv={}--Current game setting environment P.gameEnv={}--Current game setting environment
local ENV=P.gameEnv local ENV=P.gameEnv
@@ -1293,6 +1153,104 @@ local function loadAI(P,AIdata)--Load AI params
P.RS=kickList.TRS P.RS=kickList.TRS
end end
end end
local function newEmptyPlayer(id,x,y,size)
local P={id=id}
players[id]=P
players.alive[id]=P
--Inherit functions of player class
for k,v in next,player do P[k]=v end
if P.id==1 and game.recording then
P.pressKey=pressKey_Rec
P.releaseKey=releaseKey_Rec
else
P.pressKey=pressKey
P.releaseKey=releaseKey
end
P.update=Pupdate_alive
P.fieldOff={x=0,y=0,vx=0,vy=0}--For shake FX
P.x,P.y,P.size=x,y,size or 1
P.frameColor=frameColor[0]
P.small=P.size<.1--If draw in small mode
if P.small then
P.centerX,P.centerY=P.x+300*P.size,P.y+600*P.size
P.canvas=love.graphics.newCanvas(60,120)
P.frameWait=rnd(30,120)
P.draw=Pdraw_small
else
P.keyRec=true--If calculate keySpeed
P.centerX,P.centerY=P.x+300*P.size,P.y+370*P.size
P.absFieldX=P.x+150*P.size
P.absFieldY=P.y+60*P.size
P.draw=Pdraw_norm
P.bonus={}--Text objects
end
P.randGen=mt.newRandomGenerator(game.seed)
P.small=false
P.alive=true
P.control=false
P.timing=false
P.stat=getNewStatTable()
P.modeData={point=0,event=0,counter=0}--Data use by mode
P.keyTime={}P.keySpeed=0
P.dropTime={}P.dropSpeed=0
for i=1,10 do P.keyTime[i]=-1e5 end
for i=1,10 do P.dropTime[i]=-1e5 end
P.field,P.visTime={},{}
P.atkBuffer={sum=0}
--Royale-related
P.badge,P.strength=0,0
P.atkMode,P.swappingAtkMode=1,20
P.atker,P.atking,P.lastRecv={}
P.dropDelay,P.lockDelay=0,0
P.color={}
P.showTime=nil
P.keepVisible=true
--P.cur={bk=matrix[2], id=shapeID, color=colorID, name=nameID}
--P.sc,P.dir={0,0},0--SpinCenterCoord, direction
--P.r,P.c=0,0--row, col
--P.hd={...},same as P.cur
-- P.curX,P.curY,P.imgY,P.minY=0,0,0,0--x,y,ghostY
P.holded=false
P.next={}
P.freshTime=0
P.spinLast,P.lastClear=false,nil
P.spinSeq=0--For Ospin, each digit mean a spin
P.ctrlCount=0--Key press time, for finesse check
P.pieceCount=0--Count pieces from next, for drawing bagline
P.human=false
P.RS=kickList.TRS
-- P.newNext=nil--Call prepareSequence()to get a function to get new next
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
P.movDir,P.moving,P.downing=0,0,0--Last move key,DAS charging,downDAS charging
P.waiting,P.falling=-1,-1
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
P.combo,P.b2b=0,0
P.garbageBeneath=0
P.fieldBeneath=0
P.score1,P.b2b1=0,0
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
P.tasks={}--Tasks
P.bonus={}--Texts
P.endCounter=0--Used after gameover
P.result=nil--String:"WIN"/"K.O."
return P
end
--------------------------</Lib Func>-------------------------- --------------------------</Lib Func>--------------------------
--------------------------<FX>-------------------------- --------------------------<FX>--------------------------
@@ -1924,7 +1882,53 @@ function player.cancel(P,N)--Cancel Garbage
end end
return off return off
end end
function player.drop(P)--Place piece do--player.drop(P)--Place piece
local b2bPoint={50,100,180,300}
local b2bATK={3,5,8,10}
local clearSCR={80,200,400}
local spinSCR={--[blockName][row]
{200,750,1300},--Z
{200,750,1300},--S
{220,700,1300},--L
{220,700,1300},--J
{250,800,1400},--T
{260,900,1700},--O
{300,1200,1700},--I
{220,800,2000,3000},--Else
}
--B2BMUL:1.2/2.0
--Techrash:1K;MUL:1.3/1.8
--Mini*=.6
local reAtk={0,0,1,1,1,2,2,3,3}
local reDef={0,1,1,2,3,3,4,4,5}
local spinName={"zspin","sspin","jspin","lspin","tspin","ospin","ispin","zspin","sspin","pspin","qspin","fspin","espin","tspin","uspin","vspin","wspin","xspin","jspin","lspin","rspin","yspin","hspin","nspin","ispin"}
local clearName={"single","double","triple","techrash","pentcrash"}
local spin_n={[0]="spin_0","spin_1","spin_2","spin_3","spin_3"}
local clear_n={"clear_1","clear_2","clear_3","clear_4","clear_4"}
local ren_n={}for i=1,11 do ren_n[i]="ren_"..i end
local finesseList={
[1]={
{1,2,1,0,1,2,2,1},
{2,2,2,1,1,2,3,2,2},
},--Z
[3]={
{1,2,1,0,1,2,2,1},
{2,2,3,2,1,2,3,3,2},
{3,4,3,2,3,4,4,3},
{2,3,2,1,2,3,3,2,2},
},--L
[6]={
{1,2,2,1,0,1,2,2,1},
},--O
[7]={
{1,2,1,0,1,2,1},
{2,2,2,2,1,1,2,2,2,2},
},--I
}
finesseList[1][3],finesseList[1][4],finesseList[7][3],finesseList[7][4]=finesseList[1][1],finesseList[1][2],finesseList[7][1],finesseList[7][2]--"2-phase" SZI
finesseList[2]=finesseList[1]--S=Z
finesseList[4],finesseList[5]=finesseList[3],finesseList[3]--J=L=T
function player.drop(P)--Place piece
local _ local _
local CHN=VOC.getFreeChannel() local CHN=VOC.getFreeChannel()
P.dropTime[11]=ins(P.dropTime,1,game.frame)--Update speed dial P.dropTime[11]=ins(P.dropTime,1,game.frame)--Update speed dial
@@ -2348,6 +2352,7 @@ function player.drop(P)--Place piece
--Stereo SFX --Stereo SFX
if P.human then SFX.fieldPlay("lock",nil,P)end if P.human then SFX.fieldPlay("lock",nil,P)end
end
end end
--------------------------</Methods>-------------------------- --------------------------</Methods>--------------------------

View File

@@ -131,6 +131,7 @@ do--calculator
function Pnt.calculator() function Pnt.calculator()
local S=sceneTemp local S=sceneTemp
gc.setColor(1,1,1)
gc.setLineWidth(4) gc.setLineWidth(4)
gc.rectangle("line",100,80,650,150) gc.rectangle("line",100,80,650,150)
setFont(45) setFont(45)