旋转中心和朝向信息放入方块对象中,修复+修改出块高度,修复无限上踢bug,整理代码

This commit is contained in:
MrZ626
2021-03-01 21:05:32 +08:00
parent a9c892e6c7
commit e71bf616f2
6 changed files with 69 additions and 47 deletions

View File

@@ -27,7 +27,7 @@ function SFX.init(list)
SFX.loadOne=nil
function SFX.fieldPlay(s,v,P)
SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15)
SFX.play(s,v,(P.curX+P.cur.sc[2]-5.5)*.15)
end
function SFX.play(s,vol,pos)
if SETTING.sfx==0 or vol==0 then return end

View File

@@ -79,7 +79,7 @@ if _CC then
P.holdTime=P.gameEnv.holdCount
P.cur=rem(P.nextQueue,1)
P.sc,P.dir=spinCenters[P.cur.id][0],0
P.cur.sc,P.cur.dir=spinCenters[P.cur.id][0],0--TODO
P.curX,P.curY=blockPos[P.cur.id],21+ceil(P.fieldBeneath/30)-#P.cur.bk+min(int(#P.field*.2),2)
P:newNext()

View File

@@ -121,7 +121,9 @@ do
[31]={{ 0,-1},{ 0, 1},{-1, 0},{ 0,-2},{ 0, 2}},
},--T
function(P,d)
P:freshBlock("fresh")
if P.gameEnv.easyFresh then
P:freshBlock("fresh")
end
if P.gameEnv.ospin then
local x,y=P.curX,P.curY
if y==P.ghoY and((P:solid(x-1,y)or P:solid(x-1,y+1)))and(P:solid(x+2,y)or P:solid(x+2,y+1))then
@@ -140,7 +142,7 @@ do
C.id=id
C.bk=bk
P.curX,P.curY=x,y
P.dir,P.sc=dir,spinCenters[id][dir]
P.cur.dir,P.cur.sc=dir,spinCenters[id][dir]
P.spinLast=2
P.stat.rotate=P.stat.rotate+1
P:freshBlock("move")

View File

@@ -4,7 +4,7 @@ local gc_draw,gc_print,gc_line,gc_rectangle,gc_circle=gc.draw,gc.print,gc.line,g
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local TIME=TIME
local int,ceil,rnd=math.floor,math.ceil,math.random
local max,min,sin=math.max,math.min,math.sin
local max,min,sin,modf=math.max,math.min,math.sin,math.modf
local SCR=SCR
local setFont,mStr=setFont,mStr
@@ -212,8 +212,9 @@ local function drawBlock(P,clr)
end
local function drawNextPreview(P,B)
gc_setColor(1,1,1,.8)
local y=int(21-modf(B.sc[1]))+ceil(P.fieldBeneath/30)
B=B.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*(1-y-i))
@@ -591,13 +592,13 @@ function draw.norm(P)
local curColor=P.cur.color
local trans=P.lockDelay/ENV.lock
local centerX=30*(P.curX+P.sc[2])-15
local centerX=30*(P.curX+P.cur.sc[2])-15
--Draw ghost & rotation center
if ENV.ghost then drawGhost(P,curColor)end
if ENV.center and ENV.ghost then
gc_setColor(1,1,1,trans*ENV.center)
gc_draw(IMG.spinCenter,centerX,-30*(P.ghoY+P.sc[1])+15,nil,nil,nil,4,4)
gc_draw(IMG.spinCenter,centerX,-30*(P.ghoY+P.cur.sc[1])+15,nil,nil,nil,4,4)
end
local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
@@ -608,7 +609,7 @@ function draw.norm(P)
drawBlock(P,curColor)
if ENV.center then
gc_setColor(1,1,1,ENV.center)
gc_draw(IMG.spinCenter,centerX,-30*(P.curY+P.sc[1])+15,nil,nil,nil,4,4)
gc_draw(IMG.spinCenter,centerX,-30*(P.curY+P.cur.sc[1])+15,nil,nil,nil,4,4)
end
end
gc_translate(0,dy)
@@ -616,7 +617,7 @@ function draw.norm(P)
--Draw next preview
if ENV.nextPos and P.nextQueue[1]then
drawNextPreview(P,P.nextQueue[1].bk)
drawNextPreview(P,P.nextQueue[1])
end
gc.setScissor()
@@ -748,13 +749,13 @@ function draw.norm_remote(P)
local curColor=P.cur.color
local trans=P.lockDelay/ENV.lock
local centerX=30*(P.curX+P.sc[2])-15
local centerX=30*(P.curX+P.cur.sc[2])-15
--Draw ghost & rotation center
if ENV.ghost then drawGhost(P,curColor)end
if ENV.center and ENV.ghost then
gc_setColor(1,1,1,trans*ENV.center)
gc_draw(IMG.spinCenter,centerX,-30*(P.ghoY+P.sc[1])+15,nil,nil,nil,4,4)
gc_draw(IMG.spinCenter,centerX,-30*(P.ghoY+P.cur.sc[1])+15,nil,nil,nil,4,4)
end
local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
@@ -765,7 +766,7 @@ function draw.norm_remote(P)
drawBlock(P,curColor)
if ENV.center then
gc_setColor(1,1,1,ENV.center)
gc_draw(IMG.spinCenter,centerX,-30*(P.curY+P.sc[1])+15,nil,nil,nil,4,4)
gc_draw(IMG.spinCenter,centerX,-30*(P.curY+P.cur.sc[1])+15,nil,nil,nil,4,4)
end
end
gc_translate(0,dy)
@@ -773,7 +774,7 @@ function draw.norm_remote(P)
--Draw next preview
if ENV.nextPos and P.nextQueue[1]then
drawNextPreview(P,P.nextQueue[1].bk)
drawNextPreview(P,P.nextQueue[1])
end
gc.setScissor()

View File

@@ -128,8 +128,16 @@ local function newEmptyPlayer(id,mini)
P.showTime=false
P.keepVisible=true
--P.cur={bk=matrix[2], id=shapeID, color=colorID, name=nameID}
--P.sc,P.dir={0,0},0--SpinCenterCoord, direction
--[[
P.cur={
id=shapeID,
bk=matrix[2],
sc=table[2],
dir=direction,
name=nameID
color=colorID,
}
]]
-- P.curX,P.curY,P.ghoY,P.minY=0,0,0,0--x,y,ghostY
P.holdQueue={}
P.holdTime=0

View File

@@ -5,7 +5,7 @@
local Player={}--Player class
local int,ceil,rnd=math.floor,math.ceil,math.random
local max,min=math.max,math.min
local max,min,modf=math.max,math.min,math.modf
local ins,rem=table.insert,table.remove
local ct=coroutine
@@ -102,7 +102,7 @@ end
function Player.createBeam(P,R,send,color)
local x1,y1,x2,y2
if P.mini then x1,y1=P.centerX,P.centerY
else x1,y1=P.x+(30*(P.curX+P.sc[2])-30+15+150)*P.size,P.y+(600-30*(P.curY+P.sc[1])+15)*P.size
else x1,y1=P.x+(30*(P.curX+P.cur.sc[2])-30+15+150)*P.size,P.y+(600-30*(P.curY+P.cur.sc[1])+15)*P.size
end
if R.small then x2,y2=R.centerX,R.centerY
else x2,y2=R.x+308*R.size,R.y+450*R.size
@@ -437,7 +437,7 @@ end
function Player.freshBlock(P,mode)--string mode: push/move/fresh/newBlock
local ENV=P.gameEnv
--Fresh ghost
if(mode=="push"or mode=="move"or mode=="newBlock")and P.cur then
if(mode=="move"or mode=="newBlock"or mode=="push")and P.cur then
local CB=P.cur.bk
P.ghoY=min(#P.field+1,P.curY)
if P._20G or ENV.sdarr==0 and P.keyPressing[7]and P.downing>ENV.sddas then
@@ -471,7 +471,7 @@ function Player.freshBlock(P,mode)--string mode: push/move/fresh/newBlock
end
--Fresh delays
if mode=="move"or mode=="fresh"or mode=="newBlock"then
if mode=="move"or mode=="newBlock"or P.gameEnv.easyFresh and mode=="fresh"then
local d0,l0=ENV.drop,ENV.lock
if ENV.easyFresh then
if P.lockDelay<l0 and P.freshTime>0 then
@@ -531,15 +531,12 @@ end
local spawnSFX_name={}for i=1,7 do spawnSFX_name[i]="spawn_"..i end
function Player.resetBlock(P)
local B=P.cur.bk
local sc=P.cur.sc
local id=P.cur.id
local face=P.gameEnv.face[id]
local sc=scs[id][face]
P.sc=sc --Spin center
P.dir=face --Block direction
P.curX=int(6-#B[1]*.5)
local y=21+ceil(P.fieldBeneath/30)
local y=int(21-modf(sc[1]))+ceil(P.fieldBeneath/30)
P.curY=y
P.minY=y+sc[2]
P.minY=y+sc[1]
local _=P.keyPressing
--IMS
@@ -581,18 +578,11 @@ end
function Player.spin(P,d,ifpre)
local iki=P.RS[P.cur.id]
if type(iki)=="table"then
local idir=(P.dir+d)%4
local idir=(P.cur.dir+d)%4
local icb=BLOCKS[P.cur.id][idir]
local isc=scs[P.cur.id][idir]
local ix,iy=P.curX+P.sc[2]-isc[2],P.curY+P.sc[1]-isc[1]
iki=iki[P.dir*10+idir]
if not iki then
if P.gameEnv.easyFresh then
P:freshBlock("move")
end
SFX.fieldPlay(ifpre and"prerotate"or"rotate",nil,P)
return
end
local ix,iy=P.curX+P.cur.sc[2]-isc[2],P.curY+P.cur.sc[1]-isc[1]
iki=iki[P.cur.dir*10+idir]
for test=1,#iki do
local x,y=ix+iki[test][1],iy+iki[test][2]
if not P:ifoverlap(icb,x,y)and(P.freshTime>=0 or iki[test][2]<0)then
@@ -600,13 +590,13 @@ function Player.spin(P,d,ifpre)
if P.gameEnv.moveFX and P.gameEnv.block then
P:createMoveFX()
end
P.curX,P.curY,P.dir=ix,iy,idir
P.sc,P.cur.bk=scs[P.cur.id][idir],icb
P.curX,P.curY,P.cur.dir=ix,iy,idir
P.cur.sc,P.cur.bk=isc,icb
P.spinLast=test==2 and 0 or 1
if not ifpre then
P:freshBlock("move")
end
if iki[test][2]>0 and not P.gameEnv.easyFresh then
if iki[test][2]>0 and P.curY~=P.imgY then
P.freshTime=P.freshTime-1
end
@@ -619,14 +609,15 @@ function Player.spin(P,d,ifpre)
end
elseif iki then
iki(P,d)
else
P:freshBlock("move")
SFX.fieldPlay(ifpre and"prerotate"or"rotate",nil,P)
end
end
function Player.hold(P,ifpre)
if P.holdTime>0 and(ifpre or P.waiting==-1)then
if #P.holdQueue<P.gameEnv.holdCount and P.nextQueue[1]then--Skip
local C=P.cur
C.bk=BLOCKS[C.id][P.gameEnv.face[C.id]]
ins(P.holdQueue,C)
ins(P.holdQueue,P:getBlock(P.cur.id))
local t=P.holdTime
P:popNext(true)
@@ -646,7 +637,7 @@ function Player.hold(P,ifpre)
if C then
C.bk=BLOCKS[C.id][P.gameEnv.face[C.id]]
ins(P.holdQueue,C)
ins(P.holdQueue,P:getBlock(C.id))
end
P.cur=rem(P.holdQueue,1)
@@ -680,9 +671,29 @@ function Player.hold(P,ifpre)
end
end
function Player.getBlock(P,n)--Get a block(id=n) object
local E=P.gameEnv
local dir=E.face[n]
return{
id=n,
bk=BLOCKS[n][dir],
sc=scs[n][dir],
dir=dir,
name=n,
color=E.bone and 17 or E.skin[n],
}
end
function Player.getNext(P,n)--Push a block(id=n) to nextQueue
local E=P.gameEnv
ins(P.nextQueue,{bk=BLOCKS[n][E.face[n]],id=n,color=E.bone and 17 or E.skin[n],name=n})
local dir=E.face[n]
ins(P.nextQueue,{
id=n,
bk=BLOCKS[n][dir],
sc=scs[n][dir],
dir=dir,
name=n,
color=E.bone and 17 or E.skin[n],
})
end
function Player.popNext(P,ifhold)--Pop nextQueue to hand
if not ifhold then
@@ -910,7 +921,7 @@ do--Player.drop(P)--Place piece
--Tri-corner spin check
if P.spinLast then
if C.id<6 then
local x,y=CX+P.sc[2],CY+P.sc[1]
local x,y=CX+P.cur.sc[2],CY+P.cur.sc[1]
local c=0
if P:solid(x-1,y+1)then c=c+1 end
if P:solid(x+1,y+1)then c=c+1 end
@@ -1059,7 +1070,7 @@ do--Player.drop(P)--Place piece
if not finesse then
if dospin then P.ctrlCount=P.ctrlCount-2 end--Allow 2 more step for roof-less spin
local id=C.id
local d=P.ctrlCount-finesseList[id][P.dir+1][CX]
local d=P.ctrlCount-finesseList[id][P.cur.dir+1][CX]
finePts=d<=0 and 5 or max(3-d,0)
else
finePts=5
@@ -1330,7 +1341,7 @@ do--Player.drop(P)--Place piece
cscore=int(cscore)
if ENV.score then
P:showText(cscore,(P.curX+P.sc[2]-5.5)*30,(10-P.curY-P.sc[1])*30+P.fieldBeneath+P.fieldUp,40-600/(cscore+20),"score",2)
P:showText(cscore,(P.curX+P.cur.sc[2]-5.5)*30,(10-P.curY-P.cur.sc[1])*30+P.fieldBeneath+P.fieldUp,40-600/(cscore+20),"score",2)
end
piece.row,piece.dig=cc,gbcc