联网对战测试推进22

This commit is contained in:
MrZ626
2021-02-06 13:23:52 +08:00
parent 38d3e4477c
commit eec05e7eb6
18 changed files with 350 additions and 105 deletions

View File

@@ -349,6 +349,11 @@ function draw.norm(P)
--Field-related things
gc_push("transform")
gc_translate(150,0)
if P.userName then
setFont(30)
gc_setColor(1,1,1)
mStr(P.userName,150,-60)
end
--Things shake with field
gc_push("transform")

View File

@@ -50,8 +50,9 @@ local function releaseKey(P,keyID)
end
local function pressKey_Rec(P,keyID)
if P.keyAvailable[keyID]and P.alive then
ins(GAME.rep,GAME.frame+1)
ins(GAME.rep,keyID)
local L=GAME.rep
ins(L,GAME.frame+1)
ins(L,keyID)
P.keyPressing[keyID]=true
P.actList[keyID](P)
if P.control then
@@ -64,8 +65,9 @@ local function pressKey_Rec(P,keyID)
end
end
local function releaseKey_Rec(P,keyID)
ins(GAME.rep,GAME.frame+1)
ins(GAME.rep,-keyID)
local L=GAME.rep
ins(L,GAME.frame+1)
ins(L,32+keyID)
P.keyPressing[keyID]=false
end
local function newEmptyPlayer(id,mini)
@@ -186,8 +188,7 @@ end
local function loadGameEnv(P)--Load gameEnv
P.gameEnv={}--Current game setting environment
local ENV=P.gameEnv
local GAME=GAME
local SETTING=SETTING
local GAME,SETTING=GAME,SETTING
--Load game settings
for k,v in next,gameEnv0 do
if GAME.modeEnv[k]~=nil then
@@ -214,6 +215,26 @@ local function loadGameEnv(P)--Load gameEnv
end
end
end
local function loadRemoteEnv(P,conf)--Load gameEnv
P.gameEnv={}--Current game setting environment
local ENV=P.gameEnv
local GAME,SETTING=GAME,SETTING
--Load game settings
for k,v in next,gameEnv0 do
if GAME.modeEnv[k]~=nil then
v=GAME.modeEnv[k] --Mode setting
elseif conf[k]~=nil then
v=conf[k] --Game setting
elseif SETTING[k]~=nil then
v=SETTING[k] --Global setting
end
if type(v)~="table"then--Default setting
ENV[k]=v
else
ENV[k]=copyTable(v)
end
end
end
local function applyGameEnv(P)--Finish gameEnv processing
local ENV=P.gameEnv
@@ -332,16 +353,19 @@ function PLY.newDemoPlayer(id)
}
P:popNext()
end
function PLY.newRemotePlayer(id,mini,userInfo)
function PLY.newRemotePlayer(id,mini,playerData)
local P=newEmptyPlayer(id,mini)
P.type="remote"
P.update=PLY.update.remote_alive
P.userName=userInfo.name
P.userID=userInfo.id
P.stream={}
P.streamProgress=1
loadGameEnv(P)
playerData.p=P
P.userName=playerData.name
P.userID=playerData.id
loadRemoteEnv(P,playerData.conf or{})
applyGameEnv(P)
prepareSequence(P)
end

View File

@@ -224,6 +224,14 @@ function Player.setRS(P,RSname)
P.RS=kickList[RSname]
end
function Player.setConf(P,conf)
for k,v in next,conf do
if not GAME.modeEnv[k]then
P.gameEnv[k]=v
end
end
end
function Player.getHolePos(P)--Get a good garbage-line hole position
if P.garbageBeneath==0 then
return P:RND(10)
@@ -332,9 +340,21 @@ function Player.attack(P,R,send,time,...)
if SETTING.atkFX>0 then
P:createBeam(R,send,time,...)
end
R.lastRecv=P
if R.atkBuffer.sum<26 then
local B=R.atkBuffer
if GAME.net then
if P.type=="human"then
--TODO
end
if R.type=="human"then
--TODO
end
else
R:receive(P,send,time)
end
end
function Player.receive(P,A,send,time)
P.lastRecv=A
local B=P.atkBuffer
if B.sum<26 then
if send>26-B.sum then send=26-B.sum end
local m,k=#B,1
while k<=m and time>B[k].countdown do k=k+1 end
@@ -342,7 +362,7 @@ function Player.attack(P,R,send,time,...)
B[i+1]=B[i]
end
B[k]={
pos=P:RND(10),
pos=A:RND(10),
amount=send,
countdown=time,
cd0=time,
@@ -351,8 +371,8 @@ function Player.attack(P,R,send,time,...)
lv=min(int(send^.69),5),
}--Sorted insert(by time)
B.sum=B.sum+send
R.stat.recv=R.stat.recv+send
if R.sound then
P.stat.recv=P.stat.recv+send
if P.sound then
SFX.play(send<4 and"blip_1"or"blip_2",min(send+1,5)*.1)
end
end

View File

@@ -1,4 +1,5 @@
local int,max,min,abs=math.floor,math.max,math.min,math.abs
local max,min=math.max,math.min
local int,abs,rnd=math.floor,math.abs,math.random
local rem=table.remove
local function updateLine(P)--Attacks, line pushing, cam moving
@@ -108,7 +109,9 @@ local updateTasks do--updateTasks(P)
end
end
local function update_alive(P,dt)
local update={
}
function update.alive(P,dt)
local ENV=P.gameEnv
if P.timing then
local S=P.stat
@@ -336,10 +339,6 @@ local function update_alive(P,dt)
updateFXs(P,dt)
updateTasks(P)
end
local update={
alive=update_alive,
}
function update.dead(P,dt)
if P.keyRec then
local S=P.stat
@@ -369,23 +368,41 @@ function update.dead(P,dt)
updateTasks(P)
end
function update.remote_alive(P,dt)
local frmStep=GAME.frame-P.stat.frame
frmStep=
frmStep<60 and 1 or
frmStep<120 and rnd(2)or
frmStep<240 and 2 or
frmStep<480 and rnd(2,3) or
3
::readNext::
local pos=P.streamProgress
local tar=P.stream[pos]
if tar then
if P.stat.frame==tar then
local eventTime=P.stream[pos]
if eventTime then
if P.stat.frame==eventTime then
local key=P.stream[pos+1]
if key>0 then--Press key
if key==0 then--Just wait
elseif key<=32 then--Press key
P:pressKey(key)
elseif key<0 then--Release key
P:releaseKey(-key)
else--Receiving garbage
--TODO:
elseif key<=64 then--Release key
P:releaseKey(key-32)
elseif key>1023 then--Receiving garbage
local line=key%1024
local amount=int(key/1024)%256
local color=int(key/262144)%256
local sid=int(key/67108864)%256
local time=int(key/17179869184)%256
P:receive()
--TODO
end
P.streamProgress=pos+2
goto readNext
end
update_alive(P,dt)
update.alive(P,dt)
end
if frmStep>1 then
frmStep=frmStep-1
goto readNext
end
end
return update