diff --git a/parts/net.lua b/parts/net.lua index 25d26687..1bb1dd40 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -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 diff --git a/parts/netPlayer.lua b/parts/netPlayer.lua index f1f05b09..9dcf8761 100644 --- a/parts/netPlayer.lua +++ b/parts/netPlayer.lua @@ -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] diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index a810a5e6..25026de4 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -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