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