联网玩家模块升级,顺序将按照游戏排名变化

This commit is contained in:
MrZ626
2021-06-05 14:31:17 +08:00
parent 6d937d91d2
commit 8185e36839
4 changed files with 70 additions and 61 deletions

View File

@@ -17,11 +17,20 @@ return{
bgm={'battle','cruelty','distortion','far','final','hope','magicblock','new era','push','race','rockblock','secret7th','secret8th','shining terminal','storm','super7th','warped','waterfall','moonbeam'},
},
load=function()
PLY.newPlayer(1)
PLAYERS[1].sid=netPLY.getSID(USER.uid)
local N=2
for i=2,netPLY.getCount()do
local p=netPLY.rawgetPLY(i)
local L=TABLE.copy(netPLY.list)
local N=1
for i,p in next,L do
if p.uid==USER.uid then
if p.connected then
PLY.newPlayer(1)
PLAYERS[1].sid=netPLY.getSID(USER.uid)
N=2
end
table.remove(L,i)
break
end
end
for _,p in next,L do
if p.connected then
PLY.newRemotePlayer(N,false,p)
N=N+1

View File

@@ -494,6 +494,7 @@ function NET.updateWS_play()
NET.spectate=false
if NET.spectate then NET.signal_setMode(2) end
if SCN.socketRead then SCN.socketRead('finish',d)end
netPLY.freshPos()
NET.wsclose_stream()
end
else

View File

@@ -5,7 +5,7 @@ local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
local rnd,min=math.random,math.min
local sin,cos=math.sin,math.cos
local ins,rem=table.insert,table.remove
local ins=table.insert
local setFont=setFont
local posLists={
@@ -63,64 +63,66 @@ local posLists={
end)(),
}
local posList
local function _placeSort(a,b)return a.place<b.place end
local netPLY={list={}}
local PLY=netPLY.list
local function getPLY(uid)
for i=1,#PLY do
if PLY[i].uid==uid then
return PLY[i]
end
end
end
local PLYlist,PLYmap={},{}
local function freshPosList()
if #PLY<=5 then
table.sort(PLYlist,_placeSort)
if #PLYlist<=5 then
posList=posLists[1]
elseif #PLY<=17 then
elseif #PLYlist<=17 then
posList=posLists[2]
elseif #PLY<=31 then
elseif #PLYlist<=31 then
posList=posLists[3]
elseif #PLY<=49 then
elseif #PLYlist<=49 then
posList=posLists[4]
else--if #PLY<=99 then
posList=posLists[5]
end
end
local netPLY={
list=PLYlist,
map=PLYmap,
freshPos=freshPosList,
}
function netPLY.clear()for _=1,netPLY.getCount()do rem(PLY)end end
function netPLY.clear()
TABLE.cut(PLYlist)
TABLE.clear(PLYmap)
end
function netPLY.add(p)
p.connected=false
ins(PLY,p.uid==USER.uid and 1 or #PLY+1,p)
p.username=USERS.getUsername(p.uid)
p.place=1e99
p.stat={}
local a=rnd()*6.2832
p.x,p.y,p.w,p.h=640+2600*cos(a),360+2600*sin(a),47,47
freshPosList()
end
function netPLY.freshPos()
ins(PLYlist,p)
PLYmap[p.uid]=p
freshPosList()
end
function netPLY.getCount()return #PLY end
function netPLY.rawgetPLY(i)return PLY[i]end
function netPLY.getSID(uid)return getPLY(uid).sid end
function netPLY.getStat(uid)return getPLY(uid).stat end
function netPLY.getSelfJoinMode()return PLY[1].mode end
function netPLY.getSelfReady()return PLY[1].mode>0 end
function netPLY.getCount()return #PLYlist end
function netPLY.getSID(uid)return PLYmap[uid].sid end
function netPLY.getStat(uid)return PLYmap[uid].stat end
function netPLY.getSelfJoinMode()return PLYmap[USER.uid].mode end
function netPLY.getSelfReady()return PLYmap[USER.uid].mode>0 end
function netPLY.setPlayerObj(ply,p)ply.p=p end
function netPLY.setConf(uid,config)getPLY(uid).config=config end
function netPLY.setConf(uid,config)PLYmap[uid].config=config end
function netPLY.setJoinMode(uid,ready)
for i,p in next,PLY do
for _,p in next,PLYlist do
if p.uid==uid then
if p.mode~=ready then
p.mode=ready
if ready==0 then NET.allReady=false end
SFX.play('spin_0',.6)
if i==1 then
if p.uid==USER.uid then
NET.unlock('ready')
elseif PLY[1].mode==0 then
for j=2,#PLY do
if PLY[j].mode==0 then
elseif PLYmap[USER.uid].mode==0 then
for j=1,#PLYlist do
if not p.uid==USER.uid and PLYlist[j].mode==0 then
return
end
end
@@ -131,20 +133,26 @@ function netPLY.setJoinMode(uid,ready)
end
end
end
function netPLY.setConnect(uid)getPLY(uid).connected=true end
function netPLY.setStat(uid)getPLY(uid).connected=true end
function netPLY.setConnect(uid)PLYmap[uid].connected=true end
function netPLY.setPlace(uid,place)PLYmap[uid].place=place end
function netPLY.setStat(uid,S)
local p=PLYmap[uid]
p.stat.lpm=("%.1f %s"):format(S.row/S.time*60,text.radarData[5])
p.stat.apm=("%.1f %s"):format(S.atk/S.time*60,text.radarData[3])
p.stat.adpm=("%.1f %s"):format((S.atk+S.dig)/S.time*60,text.radarData[2])
end
function netPLY.resetState()
for i=1,#PLY do
PLY[i].mode=0
PLY[i].connected=false
for i=1,#PLYlist do
PLYlist[i].mode=0
PLYlist[i].connected=false
end
end
local selP,mouseX,mouseY
function netPLY.mouseMove(x,y)
selP=nil
for i=1,#PLY do
local p=PLY[i]
for i=1,#PLYlist do
local p=PLYlist[i]
if x>p.x and y>p.y and x<p.x+p.w and y<p.y+p.h then
mouseX,mouseY=x,y
selP=p
@@ -154,8 +162,8 @@ function netPLY.mouseMove(x,y)
end
function netPLY.update()
for i=1,#PLY do
local p=PLY[i]
for i=1,#PLYlist do
local p=PLYlist[i]
local t=posList[i]
p.x=p.x*.9+t.x*.1
p.y=p.y*.9+t.y*.1
@@ -169,8 +177,8 @@ local function plyStencil()
gc_rectangle('fill',0,0,stencilW,stencilH)
end
function netPLY.draw()
for i=1,#PLY do
local p=PLY[i]
for i=1,#PLYlist do
local p=PLYlist[i]
gc_translate(p.x,p.y)
--Rectangle
gc_setColor(COLOR[

View File

@@ -229,22 +229,18 @@ function scene.socketRead(cmd,d)
end
elseif cmd=='finish'then
playing=false
stat=true
love.keyboard.setKeyRepeat(true)
table.sort(d.result,_playerSort)
NET.resultList=d.result
for _,p in next,NET.resultList do
p.username=USERS.getUsername(p.uid)
local S
for _,P in next,PLAYERS do
if P.uid==p.uid then
S=P.stat
netPLY.setStat(p.uid,P.stat)
netPLY.setPlace(p.uid,p.place)
break
end
end
p.lpm=("%.1f %s"):format(S.row/S.time*60,text.radarData[5])
p.apm=("%.1f %s"):format(S.atk/S.time*60,text.radarData[3])
p.adpm=("%.1f %s"):format((S.atk+S.dig)/S.time*60,text.radarData[2])
end
netPLY.resetState()
elseif cmd=='stream'then
@@ -334,13 +330,8 @@ function scene.draw()
local L=NET.resultList
for i=1,#L do
local p=L[i]
setFont(30)
gc_print("-"..p.place.."-",100,60+40*i)
setFont(25)
gc_print(p.username,160,60+40*i)
gc_print(p.lpm,340,60+40*i)
gc_print(p.apm,490,60+40*i)
gc_print(p.adpm,640,60+40*i)
setFont(30)gc_print("-"..p.place.."-",100,58+40*i)
setFont(25)gc_print(p.username,160,60+40*i)
end
else
--Users