联网推进(修改增减玩家相关)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
local data=love.data
|
local data=love.data
|
||||||
|
local ins,rem=table.insert,table.remove
|
||||||
local NET={
|
local NET={
|
||||||
login=false,
|
login=false,
|
||||||
allow_online=false,
|
allow_online=false,
|
||||||
@@ -294,21 +295,49 @@ function NET.updateWS_play()
|
|||||||
if res.type=="Self"then
|
if res.type=="Self"then
|
||||||
--Create room
|
--Create room
|
||||||
TABLE.clear(PLY_NET)
|
TABLE.clear(PLY_NET)
|
||||||
local d=res.data
|
if data.players then
|
||||||
table.insert(PLY_NET,{
|
for _,p in next,data.players do
|
||||||
conf=dumpBasicConfig(),
|
ins(PLY_NET,{
|
||||||
name=USER.name,
|
sid=p.sid,
|
||||||
uid=USER.id,
|
uid=p.uid,
|
||||||
sid=d.sid,
|
name=p.username,
|
||||||
ready=d.ready,
|
conf=p.config,
|
||||||
|
ready=p.ready,
|
||||||
})
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
loadGame("netBattle",true,true)
|
loadGame("netBattle",true,true)
|
||||||
_unlock("enterRoom")
|
_unlock("enterRoom")
|
||||||
else
|
else
|
||||||
--Others join room
|
--Load other players
|
||||||
|
ins(PLY_NET,{
|
||||||
|
sid=data.sid,
|
||||||
|
uid=data.uid,
|
||||||
|
name=data.username,
|
||||||
|
conf=data.config,
|
||||||
|
ready=data.ready,
|
||||||
|
})
|
||||||
SCN.socketRead("Join",res.data)
|
SCN.socketRead("Join",res.data)
|
||||||
end
|
end
|
||||||
elseif res.action==3 then--Player leave
|
elseif res.action==3 then--Player leave
|
||||||
|
for i=1,#PLY_NET do
|
||||||
|
if PLY_NET[i].id==data.uid then
|
||||||
|
rem(PLY_NET,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#PLAYERS do
|
||||||
|
if PLAYERS[i].userID==data.uid then
|
||||||
|
rem(PLAYERS,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#PLY_ALIVE do
|
||||||
|
if PLY_ALIVE[i].userID==data.uid then
|
||||||
|
rem(PLY_ALIVE,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
SCN.socketRead("Leave",res.data)
|
SCN.socketRead("Leave",res.data)
|
||||||
elseif res.action==4 then--Player talk
|
elseif res.action==4 then--Player talk
|
||||||
SCN.socketRead("Talk",res.data)
|
SCN.socketRead("Talk",res.data)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local gc=love.graphics
|
local gc=love.graphics
|
||||||
local tc=love.touch
|
local tc=love.touch
|
||||||
|
|
||||||
local ins,rem=table.insert,table.remove
|
local ins=table.insert
|
||||||
|
|
||||||
local SCR=SCR
|
local SCR=SCR
|
||||||
local VK=virtualkey
|
local VK=virtualkey
|
||||||
@@ -9,8 +9,6 @@ local onVirtualkey=onVirtualkey
|
|||||||
local pressVirtualkey=pressVirtualkey
|
local pressVirtualkey=pressVirtualkey
|
||||||
local updateVirtualkey=updateVirtualkey
|
local updateVirtualkey=updateVirtualkey
|
||||||
|
|
||||||
local PLY_NET=PLY_NET
|
|
||||||
|
|
||||||
local hideChatBox
|
local hideChatBox
|
||||||
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=function()return hideChatBox end}
|
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=function()return hideChatBox end}
|
||||||
|
|
||||||
@@ -139,33 +137,11 @@ end
|
|||||||
|
|
||||||
function scene.socketRead(cmd,data)
|
function scene.socketRead(cmd,data)
|
||||||
if cmd=="Join"then
|
if cmd=="Join"then
|
||||||
if playerInitialized then
|
|
||||||
textBox:push{
|
textBox:push{
|
||||||
COLOR.lR,data.username,
|
COLOR.lR,data.username,
|
||||||
COLOR.dY,"#"..data.uid.." ",
|
COLOR.dY,"#"..data.uid.." ",
|
||||||
COLOR.Y,text.joinRoom,
|
COLOR.Y,text.joinRoom,
|
||||||
}
|
}
|
||||||
end
|
|
||||||
if data.players then
|
|
||||||
for _,p in next,data.players do
|
|
||||||
ins(PLY_NET,{
|
|
||||||
sid=p.sid,
|
|
||||||
uid=p.uid,
|
|
||||||
name=p.username,
|
|
||||||
conf=p.config,
|
|
||||||
ready=p.ready,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
ins(PLY_NET,{
|
|
||||||
sid=data.sid,
|
|
||||||
uid=data.uid,
|
|
||||||
name=data.username,
|
|
||||||
conf=data.config,
|
|
||||||
ready=data.ready,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
playerInitialized=true
|
|
||||||
SFX.play("click")
|
SFX.play("click")
|
||||||
if not playing then
|
if not playing then
|
||||||
resetGameData("qn")
|
resetGameData("qn")
|
||||||
@@ -176,25 +152,9 @@ function scene.socketRead(cmd,data)
|
|||||||
COLOR.dY,"#"..data.uid.." ",
|
COLOR.dY,"#"..data.uid.." ",
|
||||||
COLOR.Y,text.leaveRoom,
|
COLOR.Y,text.leaveRoom,
|
||||||
}
|
}
|
||||||
for i=1,#PLY_NET do
|
if not playing then
|
||||||
if PLY_NET[i].id==data.uid then
|
|
||||||
rem(PLY_NET,i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#PLAYERS do
|
|
||||||
if PLAYERS[i].userID==data.uid then
|
|
||||||
rem(PLAYERS,i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for i=1,#PLY_ALIVE do
|
|
||||||
if PLY_ALIVE[i].userID==data.uid then
|
|
||||||
rem(PLY_ALIVE,i)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
initPlayerPosition(true)
|
initPlayerPosition(true)
|
||||||
|
end
|
||||||
elseif cmd=="Talk"then
|
elseif cmd=="Talk"then
|
||||||
textBox:push{
|
textBox:push{
|
||||||
COLOR.W,data.username,
|
COLOR.W,data.username,
|
||||||
|
|||||||
Reference in New Issue
Block a user