整理代码
This commit is contained in:
@@ -82,6 +82,16 @@ local function wsCloseMessage(message)
|
||||
end
|
||||
end
|
||||
|
||||
--Remove player when leave
|
||||
local function removePlayer(L,sid)
|
||||
for i=1,#L do
|
||||
if L[i].sid==sid then
|
||||
rem(L,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Connect
|
||||
function NET.wsconn_app()
|
||||
WS.connect('app','/app')
|
||||
@@ -398,20 +408,10 @@ function NET.updateWS_play()
|
||||
NET.unlock('quit')
|
||||
SCN.back()
|
||||
else
|
||||
netPLY.remove(d.sid)
|
||||
--TODO
|
||||
for i=1,#PLAYERS do
|
||||
if PLAYERS[i].sid==d.sid then
|
||||
rem(PLAYERS,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
for i=1,#PLY_ALIVE do
|
||||
if PLY_ALIVE[i].sid==d.sid then
|
||||
rem(PLY_ALIVE,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
removePlayer(netPLY.list,d.sid)
|
||||
netPLY.freshPos()
|
||||
removePlayer(PLAYERS,d.sid)
|
||||
removePlayer(PLY_ALIVE,d.sid)
|
||||
if SCN.socketRead then SCN.socketRead('leave',d)end
|
||||
end
|
||||
elseif res.action==4 then--Player talk
|
||||
|
||||
@@ -94,13 +94,7 @@ function netPLY.add(p)
|
||||
p.x,p.y,p.w,p.h=640+2600*cos(a),360+2600*sin(a),47,47
|
||||
freshPosList()
|
||||
end
|
||||
function netPLY.remove(sid)
|
||||
for i=1,#PLY do
|
||||
if PLY[i].sid==sid then
|
||||
rem(PLY,i)
|
||||
break
|
||||
end
|
||||
end
|
||||
function netPLY.freshPos()
|
||||
freshPosList()
|
||||
end
|
||||
|
||||
@@ -153,7 +147,7 @@ function netPLY.mouseMove(x,y)
|
||||
end
|
||||
end
|
||||
|
||||
function netPLY.update(dt)
|
||||
function netPLY.update()
|
||||
for i=1,#PLY do
|
||||
local p=PLY[i]
|
||||
local t=posList[i]
|
||||
|
||||
@@ -224,7 +224,7 @@ function scene.update(dt)
|
||||
lastUpstreamTime=PLAYERS[1].alive and P1.frameRun or 1e99
|
||||
end
|
||||
else
|
||||
netPLY.update(dt)
|
||||
netPLY.update()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user