play场景改名game,整理代码,重构GAME.frame相关内容,修复联网录像播放不正确

This commit is contained in:
MrZ626
2021-04-17 01:39:18 +08:00
parent 444c5e571e
commit 287d5a805d
24 changed files with 81 additions and 98 deletions

View File

@@ -349,7 +349,7 @@ end
function love.focus(f)
if f then
love.timer.step()
elseif SCN.cur=="play"and SETTING.autoPause then
elseif SCN.cur=="game"and SETTING.autoPause then
pauseGame()
end
end

View File

@@ -614,7 +614,7 @@ function loadGame(M,ifQuickPlay,ifNet)--Load a mode and go to game scene
SCN.go("net_game","swipeD")
else
drawableText.modeName:set(text.modes[M][1].." "..text.modes[M][2])
SCN.go("play",ifQuickPlay and"swipeD"or"fade_togame")
SCN.go("game",ifQuickPlay and"swipeD"or"fade_togame")
SFX.play("enter")
end
end
@@ -731,7 +731,7 @@ do--function resetGameData(args)
end
function resetGameData(args,seed)
if not args then args=""end
if PLAYERS[1]and not GAME.replaying and(GAME.frame>400 or GAME.result)then
if PLAYERS[1]and not GAME.replaying and(PLAYERS[1].frameRun>400 or GAME.result)then
mergeStat(STAT,PLAYERS[1].stat)
STAT.todayTime=STAT.todayTime+PLAYERS[1].stat.time
end
@@ -740,11 +740,11 @@ do--function resetGameData(args)
GAME.warnLVL0=0
GAME.warnLVL=0
if args:find("r")then
GAME.frame=0
GAME.frameStart=0
GAME.recording=false
GAME.replaying=1
else
GAME.frame=args:find("n")and 0 or 150-SETTING.reTime*15
GAME.frameStart=args:find("n")and 0 or 150-SETTING.reTime*15
GAME.seed=seed or rnd(1046101471,2662622626)
GAME.pauseTime=0
GAME.pauseCount=0
@@ -790,39 +790,10 @@ do--function resetGameData(args)
collectgarbage()
end
end
function gameStart()--Call when countdown finish (GAME.frame==180)
SFX.play("start")
for P=1,#PLAYERS do
P=PLAYERS[P]
P.control=true
P.timing=true
P:popNext()
end
end
function checkStart()
if GAME.frame<=180 then
if GAME.frame==180 then
gameStart()
elseif GAME.frame==60 or GAME.frame==120 then
SFX.play("ready")
end
for p=1,#PLAYERS do
local P=PLAYERS[p]
if P.movDir~=0 then
if P.moving<P.gameEnv.das then
P.moving=P.moving+1
end
else
P.moving=0
end
end
return true
end
end
function checkWarning()
local P1=PLAYERS[1]
if P1.alive then
if GAME.frame%26==0 then
if P1.frameRun%26==0 then
local F=P1.field
local height=0--Max height of row 4~7
for x=4,7 do
@@ -847,7 +818,7 @@ function checkWarning()
elseif GAME.warnLVL>0 then
GAME.warnLVL=max(GAME.warnLVL-.026,0)
end
if GAME.warnLVL>1.126 and GAME.frame%30==0 then
if GAME.warnLVL>1.126 and P1.frameRun%30==0 then
SFX.fplay("warning",SETTING.sfx_warn)
end
end

View File

@@ -190,7 +190,6 @@ GAME={--Global game data
init=false, --If need initializing game when enter scene-play
net=false, --If play net game
frame=0, --Frame count
result=false, --Game result (string)
rank=false, --Rank reached
pauseTime=0, --Time paused

View File

@@ -8,7 +8,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"and P.atkBuffer.sum==0 then
if P.control and P.atkBuffer.sum==0 then
local p=#P.atkBuffer+1
local B,D=P.atkBuffer,P.modeData
local t

View File

@@ -7,7 +7,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"and P.atkBuffer.sum<4 then
if P.control and P.atkBuffer.sum<4 then
local p=#P.atkBuffer+1
local B,D=P.atkBuffer,P.modeData
local s

View File

@@ -9,7 +9,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.counter=D.counter+1
local t=math.max(240-2*D.wave,40)

View File

@@ -9,7 +9,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.counter=D.counter+1
local t=math.max(360-D.wave*2,60)

View File

@@ -7,7 +7,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(90,180-D.wave)then

View File

@@ -6,7 +6,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(30,80-.3*D.wave)then

View File

@@ -6,7 +6,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(60,150-2*D.wave)and P.atkBuffer.sum<4 then

View File

@@ -6,7 +6,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
local B=P.atkBuffer

View File

@@ -6,7 +6,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(60,150-D.wave)and P.atkBuffer.sum<20 then

View File

@@ -6,7 +6,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(90,180-2*D.wave)and P.atkBuffer.sum<8 then

View File

@@ -8,7 +8,7 @@ return{
task=function(P)
while true do
YIELD()
if P.control and SCN.cur=="play"then
if P.control then
local D=P.modeData
D.timer=D.timer+1
if D.timer>=math.max(300,600-10*D.wave)and P.atkBuffer.sum<20 then

View File

@@ -426,12 +426,12 @@ local function drawMission(P)
end
local function drawStartCounter(P)
gc_setColor(1,1,1)
if GAME.frame<180 then
if GAME.frame==0 then
if P.frameRun<180 then
if P.frameRun==0 then
setFont(70)
mStr(P.ready and text.beReady or text.notReady,305,220)
else
local count=179-GAME.frame
local count=179-P.frameRun
gc_push("transform")
gc_translate(305,220)
setFont(95)

View File

@@ -43,7 +43,7 @@ local function pressKey(P,keyID)
P.keyPressing[keyID]=true
P.actList[keyID](P)
if P.control then
ins(P.keyTime,1,GAME.frame)
ins(P.keyTime,1,P.frameRun)
P.keyTime[11]=nil
end
P.stat.key=P.stat.key+1
@@ -55,12 +55,12 @@ end
local function pressKey_Rec(P,keyID)
if P.keyAvailable[keyID]and P.alive then
local L=GAME.rep
ins(L,GAME.frame)
ins(L,P.frameRun)
ins(L,keyID)
P.keyPressing[keyID]=true
P.actList[keyID](P)
if P.control then
ins(P.keyTime,1,GAME.frame)
ins(P.keyTime,1,P.frameRun)
P.keyTime[11]=nil
end
P.stat.key=P.stat.key+1
@@ -68,7 +68,7 @@ local function pressKey_Rec(P,keyID)
end
local function releaseKey_Rec(P,keyID)
local L=GAME.rep
ins(L,GAME.frame)
ins(L,P.frameRun)
ins(L,32+keyID)
P.keyPressing[keyID]=false
end
@@ -114,6 +114,7 @@ local function newEmptyPlayer(id,mini)
P.randGen=love.math.newRandomGenerator(GAME.seed)
P.frameRun=GAME.frameStart
P.alive=true
P.control=false
P.timing=false
@@ -354,6 +355,7 @@ function PLY.newDemoPlayer(id)
P.sound=true
P.demo=true
P.frameRun=180
P.draw=PLY.draw.demo
P.control=true
GAME.modeEnv=DemoEnv

View File

@@ -339,7 +339,7 @@ function Player:attack(R,send,time,line,fromStream)
local atkFX=self.gameEnv.atkFX
if GAME.net then
if self.type=="human"then--Local player attack others
ins(GAME.rep,GAME.frame)
ins(GAME.rep,self.frameRun)
ins(GAME.rep,
R.sid+
send*0x100+
@@ -352,7 +352,7 @@ function Player:attack(R,send,time,line,fromStream)
end
end
if fromStream and R.type=="human"then--Local player receiving lines
ins(GAME.rep,GAME.frame)
ins(GAME.rep,self.frameRun)
ins(GAME.rep,
self.sid+
send*0x100+
@@ -960,7 +960,7 @@ do--Player.drop(self)--Place piece
function Player:drop()
local _
local CHN=VOC.getFreeChannel()
self.dropTime[11]=ins(self.dropTime,1,GAME.frame)--Update speed dial
self.dropTime[11]=ins(self.dropTime,1,self.frameRun)--Update speed dial
local ENV=self.gameEnv
local Stat=self.stat
local piece=self.lastPiece
@@ -1609,7 +1609,7 @@ function tick_autoPause()
while true do
yield()
time=time+1
if SCN.cur~="play"or GAME.frame<180 then
if SCN.cur~="game"or PLAYERS[1].frameRun<180 then
return
elseif time==120 then
pauseGame()
@@ -1697,7 +1697,7 @@ function Player:die()--Called both when win/lose!
end
if GAME.net then
if self.id==1 then
ins(GAME.rep,GAME.frame)
ins(GAME.rep,self.frameRun)
ins(GAME.rep,0)
else
if self.lastRecv and self.lastRecv.id==1 then

View File

@@ -114,8 +114,29 @@ local update={
}
function update.alive(P,dt)
local ENV=P.gameEnv
local S=P.stat
P.frameRun=P.frameRun+1
if P.frameRun<=180 then
if P.frameRun==180 then
if P.id==1 then SFX.play("start")end
P.control=true
P.timing=true
P:popNext()
elseif P.frameRun==60 or P.frameRun==120 then
if P.id==1 then SFX.play("ready")end
end
if P.movDir~=0 then
if P.moving<P.gameEnv.das then
P.moving=P.moving+1
end
else
P.moving=0
end
return true
end
if P.timing then
local S=P.stat
S.time=S.time+dt
S.frame=S.frame+1
end
@@ -123,10 +144,10 @@ function update.alive(P,dt)
--Calculate key speed
do
local v=0
for i=2,10 do v=v+i*(i-1)*72/(GAME.frame-P.keyTime[i]+1)end
for i=2,10 do v=v+i*(i-1)*72/(P.frameRun-P.keyTime[i]+1)end
P.keySpeed=P.keySpeed*.99+v*.01
v=0
for i=2,10 do v=v+i*(i-1)*72/(GAME.frame-P.dropTime[i])end
for i=2,10 do v=v+i*(i-1)*72/(P.frameRun-P.dropTime[i])end
P.dropSpeed=P.dropSpeed*.99+v*.01
end
@@ -372,17 +393,17 @@ function update.dead(P,dt)
updateTasks(P)
end
function update.remote_alive(P,dt)
local frmStep=GAME.frame-P.stat.frame
local frmDelta=PLAYERS[1].frameRun-P.frameRun
for _=1,
frmStep<20 and 1 or
frmStep<45 and rnd(2)or
frmStep<90 and 2 or
frmStep<180 and rnd(2,3) or
frmDelta<20 and 1 or
frmDelta<45 and rnd(2)or
frmDelta<90 and 2 or
frmDelta<180 and rnd(2,3) or
3
do
local eventTime=P.stream[P.streamProgress]
if eventTime then--Normal state, event forward
if P.stat.frame==eventTime then--Event time, execute action, read next so don't update immediately
if P.frameRun==eventTime then--Event time, execute action, read next so don't update immediately
local event=P.stream[P.streamProgress+1]
if event==0 then--Just wait
elseif event<=32 then--Press key

View File

@@ -14,14 +14,14 @@ function scene.update(dt)
timer=timer-dt*.8
if timer<0 then
SFX.play("click")
SCN.swapTo("play","none")
SCN.swapTo("game","none")
end
end
function scene.draw()
--Game scene
if timer*1.26<1 then
SCN.scenes.play.draw()
SCN.scenes.game.draw()
end
--Grey screen cover

View File

@@ -27,7 +27,7 @@ end
scene.mouseDown=NULL
local function restart()
resetGameData(GAME.frame<240 and"q")
resetGameData(PLAYERS[1].frameRun<240 and"q")
noKey=GAME.replaying
noTouch=noKey
end
@@ -133,7 +133,7 @@ function scene.update(dt)
_=GAME.replaying
local P1=PLAYERS[1]
local L=GAME.rep
while GAME.frame==L[_]do
while P1.frameRun==L[_]do
local key=L[_+1]
if key==0 then--Just wait
elseif key<=32 then--Press key
@@ -150,10 +150,6 @@ function scene.update(dt)
touchMoveLastFrame=false
updateVirtualkey()
GAME.frame=GAME.frame+1
--Counting, include pre-das
if checkStart()then return end
--Update players
for p=1,#PLAYERS do PLAYERS[p]:update(dt)end
@@ -162,7 +158,7 @@ function scene.update(dt)
checkWarning()
--Fresh royale target
if GAME.modeEnv.royaleMode and GAME.frame%120==0 then
if GAME.modeEnv.royaleMode and PLAYERS[1].frameRun%120==0 then
freshMostDangerous()
end
end

View File

@@ -37,7 +37,6 @@ function scene.sceneInit()
--Create demo player
destroyPlayers()
GAME.modeEnv=NONE
GAME.frame=0
GAME.seed=math.random(2e6)
PLY.newDemoPlayer(1)
PLAYERS[1]:setPosition(520,140,.8)
@@ -127,7 +126,6 @@ function scene.keyDown(key)
end
function scene.update(dt)
GAME.frame=GAME.frame+1
PLAYERS[1]:update(dt)
scrollX=scrollX-2.6
if scrollX<-tip:getWidth()then

View File

@@ -173,7 +173,7 @@ function scene.update()
end
local _=SCN.stat.tar
mapCam.zoomMethod=_=="play"and 1 or _=="mode"and 2
mapCam.zoomMethod=_=="game"and 1 or _=="mode"and 2
if mapCam.zoomMethod==1 then
_=mapCam.zoomK
if _<.8 then _=_*1.05 end

View File

@@ -199,15 +199,11 @@ function scene.update(dt)
if NET.checkPlayDisconn()then SCN.back()end
if not playing then return end
local _
local P1=PLAYERS[1]
local GAME=GAME
touchMoveLastFrame=false
updateVirtualkey()
GAME.frame=GAME.frame+1
--Counting, include pre-das
if checkStart()then return end
--Update players
for p=1,#PLAYERS do PLAYERS[p]:update(dt)end
@@ -216,16 +212,16 @@ function scene.update(dt)
checkWarning()
--Upload stream
if GAME.frame-lastUpstreamTime>8 then
if P1.frameRun-lastUpstreamTime>8 then
local stream
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
if #stream>0 then
NET.uploadRecStream(stream)
else
ins(GAME.rep,GAME.frame)
ins(GAME.rep,P1.frameRun)
ins(GAME.rep,0)
end
lastUpstreamTime=PLAYERS[1].alive and GAME.frame or 1e99
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
end
end

View File

@@ -34,7 +34,7 @@ function scene.sceneInit(org)
local P=PLAYERS[1]
local S=P.stat
timer=org=="play"and 0 or 50
timer=org=="game"and 0 or 50
local frameLostRate=(S.frame/S.time/60-1)*100
form={
@@ -113,14 +113,14 @@ function scene.sceneInit(org)
else
rank,trophy=nil
end
if org~="play"and GAME.prevBG then
if org~="game"and GAME.prevBG then
BG.set(GAME.prevBG)
end
end
function scene.sceneBack()
love.keyboard.setKeyRepeat(true)
STAT.todayTime=STAT.todayTime+PLAYERS[1].stat.time
if not GAME.replaying and(GAME.frame>400 or GAME.result)and not GAME.result then
if not GAME.replaying and(PLAYERS[1].frameRun>400 or GAME.result)and not GAME.result then
mergeStat(STAT,PLAYERS[1].stat)
FILE.save(STAT,"conf/data")
end
@@ -130,17 +130,17 @@ function scene.keyDown(key)
if key=="q"then
SCN.back()
elseif key=="escape"then
SCN.swapTo(GAME.result and"play"or"depause","none")
SCN.swapTo(GAME.result and"game"or"depause","none")
elseif key=="s"then
GAME.prevBG=BG.cur
SCN.go("setting_sound")
elseif key=="r"then
resetGameData()
SCN.swapTo("play","none")
SCN.swapTo("game","none")
elseif key=="p"then
if(GAME.result or GAME.replaying)and #PLAYERS==1 then
resetGameData("r")
SCN.swapTo("play","none")
SCN.swapTo("game","none")
end
elseif key=="o"then
if(GAME.result or GAME.replaying)and #PLAYERS==1 and not GAME.saved and saveRecording()then
@@ -166,7 +166,7 @@ local textPos={90,131,-90,131,-200,-25,-90,-181,90,-181,200,-25}
local dataPos={90,143,-90,143,-200,-13,-90,-169,90,-169,200,-13}
function scene.draw()
local T=timer*.02
if T<1 or GAME.result then SCN.scenes.play.draw()end
if T<1 or GAME.result then SCN.scenes.game.draw()end
--Dark BG
local _=T
@@ -194,7 +194,7 @@ function scene.draw()
gc.draw(drawableText.modeName,40,240)
--Infos
if GAME.frame>180 then
if PLAYERS[1].frameRun>180 then
gc.setLineWidth(2)
--Finesse rank & trophy
if rank then
@@ -264,7 +264,7 @@ function scene.draw()
end
--Radar Chart
if T>.5 and GAME.frame>180 then
if T>.5 and PLAYERS[1].frameRun>180 then
T=T*2-1
gc.setLineWidth(2)
gc.push("transform")