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

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'}, bgm={'battle','cruelty','distortion','far','final','hope','magicblock','new era','push','race','rockblock','secret7th','secret8th','shining terminal','storm','super7th','warped','waterfall','moonbeam'},
}, },
load=function() load=function()
PLY.newPlayer(1) local L=TABLE.copy(netPLY.list)
PLAYERS[1].sid=netPLY.getSID(USER.uid) local N=1
local N=2 for i,p in next,L do
for i=2,netPLY.getCount()do if p.uid==USER.uid then
local p=netPLY.rawgetPLY(i) 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 if p.connected then
PLY.newRemotePlayer(N,false,p) PLY.newRemotePlayer(N,false,p)
N=N+1 N=N+1

View File

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

View File

@@ -5,7 +5,7 @@ local gc_stencil,gc_setStencilTest=gc.stencil,gc.setStencilTest
local rnd,min=math.random,math.min local rnd,min=math.random,math.min
local sin,cos=math.sin,math.cos local sin,cos=math.sin,math.cos
local ins,rem=table.insert,table.remove local ins=table.insert
local setFont=setFont local setFont=setFont
local posLists={ local posLists={
@@ -63,64 +63,66 @@ local posLists={
end)(), end)(),
} }
local posList local posList
local function _placeSort(a,b)return a.place<b.place end
local netPLY={list={}} local PLYlist,PLYmap={},{}
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 function freshPosList() local function freshPosList()
if #PLY<=5 then table.sort(PLYlist,_placeSort)
if #PLYlist<=5 then
posList=posLists[1] posList=posLists[1]
elseif #PLY<=17 then elseif #PLYlist<=17 then
posList=posLists[2] posList=posLists[2]
elseif #PLY<=31 then elseif #PLYlist<=31 then
posList=posLists[3] posList=posLists[3]
elseif #PLY<=49 then elseif #PLYlist<=49 then
posList=posLists[4] posList=posLists[4]
else--if #PLY<=99 then else--if #PLY<=99 then
posList=posLists[5] posList=posLists[5]
end end
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) function netPLY.add(p)
p.connected=false 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 local a=rnd()*6.2832
p.x,p.y,p.w,p.h=640+2600*cos(a),360+2600*sin(a),47,47 p.x,p.y,p.w,p.h=640+2600*cos(a),360+2600*sin(a),47,47
freshPosList()
end ins(PLYlist,p)
function netPLY.freshPos() PLYmap[p.uid]=p
freshPosList() freshPosList()
end end
function netPLY.getCount()return #PLY end function netPLY.getCount()return #PLYlist end
function netPLY.rawgetPLY(i)return PLY[i]end function netPLY.getSID(uid)return PLYmap[uid].sid end
function netPLY.getSID(uid)return getPLY(uid).sid end function netPLY.getStat(uid)return PLYmap[uid].stat end
function netPLY.getStat(uid)return getPLY(uid).stat end function netPLY.getSelfJoinMode()return PLYmap[USER.uid].mode end
function netPLY.getSelfJoinMode()return PLY[1].mode end function netPLY.getSelfReady()return PLYmap[USER.uid].mode>0 end
function netPLY.getSelfReady()return PLY[1].mode>0 end
function netPLY.setPlayerObj(ply,p)ply.p=p 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) 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.uid==uid then
if p.mode~=ready then if p.mode~=ready then
p.mode=ready p.mode=ready
if ready==0 then NET.allReady=false end if ready==0 then NET.allReady=false end
SFX.play('spin_0',.6) SFX.play('spin_0',.6)
if i==1 then if p.uid==USER.uid then
NET.unlock('ready') NET.unlock('ready')
elseif PLY[1].mode==0 then elseif PLYmap[USER.uid].mode==0 then
for j=2,#PLY do for j=1,#PLYlist do
if PLY[j].mode==0 then if not p.uid==USER.uid and PLYlist[j].mode==0 then
return return
end end
end end
@@ -131,20 +133,26 @@ function netPLY.setJoinMode(uid,ready)
end end
end end
end end
function netPLY.setConnect(uid)getPLY(uid).connected=true end function netPLY.setConnect(uid)PLYmap[uid].connected=true end
function netPLY.setStat(uid)getPLY(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() function netPLY.resetState()
for i=1,#PLY do for i=1,#PLYlist do
PLY[i].mode=0 PLYlist[i].mode=0
PLY[i].connected=false PLYlist[i].connected=false
end end
end end
local selP,mouseX,mouseY local selP,mouseX,mouseY
function netPLY.mouseMove(x,y) function netPLY.mouseMove(x,y)
selP=nil selP=nil
for i=1,#PLY do for i=1,#PLYlist do
local p=PLY[i] 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 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 mouseX,mouseY=x,y
selP=p selP=p
@@ -154,8 +162,8 @@ function netPLY.mouseMove(x,y)
end end
function netPLY.update() function netPLY.update()
for i=1,#PLY do for i=1,#PLYlist do
local p=PLY[i] local p=PLYlist[i]
local t=posList[i] local t=posList[i]
p.x=p.x*.9+t.x*.1 p.x=p.x*.9+t.x*.1
p.y=p.y*.9+t.y*.1 p.y=p.y*.9+t.y*.1
@@ -169,8 +177,8 @@ local function plyStencil()
gc_rectangle('fill',0,0,stencilW,stencilH) gc_rectangle('fill',0,0,stencilW,stencilH)
end end
function netPLY.draw() function netPLY.draw()
for i=1,#PLY do for i=1,#PLYlist do
local p=PLY[i] local p=PLYlist[i]
gc_translate(p.x,p.y) gc_translate(p.x,p.y)
--Rectangle --Rectangle
gc_setColor(COLOR[ gc_setColor(COLOR[

View File

@@ -229,22 +229,18 @@ function scene.socketRead(cmd,d)
end end
elseif cmd=='finish'then elseif cmd=='finish'then
playing=false playing=false
stat=true
love.keyboard.setKeyRepeat(true) love.keyboard.setKeyRepeat(true)
table.sort(d.result,_playerSort) table.sort(d.result,_playerSort)
NET.resultList=d.result NET.resultList=d.result
for _,p in next,NET.resultList do for _,p in next,NET.resultList do
p.username=USERS.getUsername(p.uid) p.username=USERS.getUsername(p.uid)
local S
for _,P in next,PLAYERS do for _,P in next,PLAYERS do
if P.uid==p.uid then if P.uid==p.uid then
S=P.stat netPLY.setStat(p.uid,P.stat)
netPLY.setPlace(p.uid,p.place)
break break
end end
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 end
netPLY.resetState() netPLY.resetState()
elseif cmd=='stream'then elseif cmd=='stream'then
@@ -334,13 +330,8 @@ function scene.draw()
local L=NET.resultList local L=NET.resultList
for i=1,#L do for i=1,#L do
local p=L[i] local p=L[i]
setFont(30) setFont(30)gc_print("-"..p.place.."-",100,58+40*i)
gc_print("-"..p.place.."-",100,60+40*i) setFont(25)gc_print(p.username,160,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)
end end
else else
--Users --Users