From ca267fd5657e96899bd51b9fbffe9c07af77ba7d Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Thu, 8 Apr 2021 23:43:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=94=B9=E8=81=94=E7=BD=91=E7=9A=84lo?= =?UTF-8?q?ck=E5=AD=90=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=A4=A7=E6=94=B9?= =?UTF-8?q?=E5=AF=B9=E6=88=98=E7=9A=84=E7=8E=A9=E5=AE=B6=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E9=87=8D=E5=81=9A=E8=81=94=E7=BD=91?= =?UTF-8?q?=E5=AF=B9=E6=88=98=E5=87=86=E5=A4=87=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/modes/netBattle.lua | 2 +- parts/net.lua | 96 +++++++++++++++++--------------------- parts/player/draw.lua | 2 +- parts/player/init.lua | 20 ++++---- parts/player/player.lua | 6 +-- parts/player/update.lua | 4 +- parts/scenes/net_game.lua | 66 +++++++++++++++----------- parts/scenes/net_rooms.lua | 8 ++-- 8 files changed, 104 insertions(+), 100 deletions(-) diff --git a/parts/modes/netBattle.lua b/parts/modes/netBattle.lua index 1534db3f..2673b6ae 100644 --- a/parts/modes/netBattle.lua +++ b/parts/modes/netBattle.lua @@ -12,7 +12,7 @@ return{ local N=2 for i=1,#PLY_NET do if PLY_NET[i].uid==USER.uid then - PLAYERS[1].subID=PLY_NET[1].sid + PLAYERS[1].sid=PLY_NET[1].sid else PLY.newRemotePlayer(N,false,PLY_NET[i]) N=N+1 diff --git a/parts/net.lua b/parts/net.lua index d1903b7d..36b1d856 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -1,6 +1,6 @@ -local WS=WS local data=love.data local ins,rem=table.insert,table.remove +local WS,TIME=WS,TIME local NET={ login=false, allow_online=false, @@ -19,20 +19,26 @@ local mesType={ } --Lock & Unlock submodule -local locks={} -local function _lock(name,T) - if locks[name]and TIME()=locks[name]then locks[name]=TIME()+(T or 1e99) return true + else + return false end end -local function _unlock(name) - locks[name]=false +function NET.unlock(name) + locks[name]=-1e99 end -function NET.getLock(name) - return locks[name] +function NET.getlock(name) + return TIME()0 then P:createBeam(L[i],amount,P.cur.color) @@ -408,7 +408,7 @@ function update.remote_alive(P,dt) local L=PLY_ALIVE local sid=event%0x100 for i=1,#L do - if L[i].subID==sid then + if L[i].sid==sid then P:receive( L[i], int(event/0x100)%0x100,--amount diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index 973a5f47..8c9d894e 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -28,7 +28,6 @@ function scene.sceneInit() textBox.hide=true textBox:clear() - resetGameData("n") noTouch=not SETTING.VKSwitch playing=false lastUpstreamTime=0 @@ -36,7 +35,7 @@ function scene.sceneInit() end function scene.touchDown(x,y) - if noTouch then return end + if noTouch or not playing then return end local t=onVirtualkey(x,y) if t then @@ -45,7 +44,7 @@ function scene.touchDown(x,y) end end function scene.touchUp(x,y) - if noTouch then return end + if noTouch or not playing then return end local t=onVirtualkey(x,y) if t then @@ -53,7 +52,7 @@ function scene.touchUp(x,y) end end function scene.touchMove() - if noTouch or touchMoveLastFrame then return end + if noTouch or touchMoveLastFrame or not playing then return end touchMoveLastFrame=true local L=tc.getTouches() @@ -93,9 +92,7 @@ function scene.keyDown(key) VK[k].pressTime=10 end elseif key=="space"then - if not NET.getLock("ready")then - NET.signal_ready(not PLAYERS[1].ready) - end + NET.signal_ready(not PLY_NET[1].ready) end end function scene.keyUp(key) @@ -142,9 +139,6 @@ function scene.socketRead(cmd,d) COLOR.Y,text.joinRoom, } SFX.play("click") - if not playing then - resetGameData("qn") - end elseif cmd=="Leave"then textBox:push{ COLOR.lR,d.username, @@ -163,6 +157,9 @@ function scene.socketRead(cmd,d) elseif cmd=="Go"then if not playing then playing=true + for i=1,#PLY_NET do + PLY_NET[i].ready=false + end lastUpstreamTime=0 upstreamProgress=1 resetGameData("n",d.seed) @@ -171,7 +168,6 @@ function scene.socketRead(cmd,d) end elseif cmd=="Finish"then playing=false - resetGameData("n") local winnerUID for _,p in next,d.result do if p.place==1 then @@ -189,12 +185,12 @@ function scene.socketRead(cmd,d) elseif cmd=="Stream"then if d.uid~=USER.uid and playing then for _,P in next,PLAYERS do - if P.userID==d.uid then + if P.uid==d.uid then local res,stream=pcall(love.data.decode,"string","base64",d.stream) if res then pumpRecording(stream,P.stream) else - LOG.print("Bad stream from "..P.userName.."#"..P.userID) + LOG.print("Bad stream from "..P.username.."#"..P.uid) end end end @@ -237,19 +233,37 @@ function scene.update(dt) end function scene.draw() - drawFWM() + if playing then + drawFWM() - --Players - for p=textBox.hide and 1 or 2,#PLAYERS do - PLAYERS[p]:draw() + --Players + for p=textBox.hide and 1 or 2,#PLAYERS do + PLAYERS[p]:draw() + end + + --Virtual keys + drawVirtualkeys() + + --Warning + drawWarning() + else + setFont(40) + for i=1,#PLY_NET do + local p=PLY_NET[i] + + if p.ready then + gc.setColor(.4,1,.4) + else + gc.setColor(1,1,1) + end + gc.rectangle("fill",50,60+50*i+14,30,30) + + gc.setColor(.5,.5,.5) + gc.print("#"..p.uid,90,60+50*i) + gc.setColor(1,1,1) + gc.print(p.username,230,60+50*i) + end end - - --Virtual keys - drawVirtualkeys() - - --Warning - drawWarning() - --New message if textBox.new and textBox.hide then setFont(30) @@ -259,11 +273,11 @@ function scene.draw() end scene.widgetList={ textBox, - WIDGET.newKey{name="ready",x=640,y=440,w=200,h=80,color="yellow",font=40,code=pressKey"space",hide=function() + WIDGET.newKey{name="ready",x=900,y=560,w=400,h=100,color="yellow",font=40,code=pressKey"space",hide=function() return playing or not textBox.hide or - NET.getLock("ready") + NET.getlock("ready") end}, WIDGET.newKey{name="hideChat",fText="...",x=380,y=35,w=60,font=35,code=pressKey"\\"}, WIDGET.newKey{name="quit",fText="X",x=900,y=35,w=60,font=40,code=pressKey"escape"}, diff --git a/parts/scenes/net_rooms.lua b/parts/scenes/net_rooms.lua index fd8985df..eb7aed83 100644 --- a/parts/scenes/net_rooms.lua +++ b/parts/scenes/net_rooms.lua @@ -52,7 +52,7 @@ function scene.keyDown(k) end end elseif k=="return"then - if NET.getLock("fetchRoom")then return end + if NET.getlock("fetchRoom")then return end if NET.roomList[selected].private then LOG.print("Can't enter private room now") return @@ -63,7 +63,7 @@ function scene.keyDown(k) end function scene.update(dt) - if not NET.getLock("fetchRoom")then + if not NET.getlock("fetchRoom")then fetchTimer=fetchTimer-dt if fetchTimer<=0 then fetchRoom() @@ -103,8 +103,8 @@ end local function hide_noRoom()return #NET.roomList==0 end scene.widgetList={ - WIDGET.newText{name="refreshing",x=640,y=255,font=45,hide=function()return not NET.getLock("fetchRoom")end}, - WIDGET.newText{name="noRoom", x=640,y=260,font=40,hide=function()return #NET.roomList>0 or NET.getLock("fetchRoom")end}, + WIDGET.newText{name="refreshing",x=640,y=255,font=45,hide=function()return not NET.getlock("fetchRoom")end}, + WIDGET.newText{name="noRoom", x=640,y=260,font=40,hide=function()return #NET.roomList>0 or NET.getlock("fetchRoom")end}, WIDGET.newKey{name="refresh", x=240,y=620,w=140,h=140,font=35,code=fetchRoom, hide=function()return fetchTimer>3.26 end}, WIDGET.newKey{name="new", x=440,y=620,w=140,h=140,font=25,code=pressKey"n"}, WIDGET.newKey{name="join", x=640,y=620,w=140,h=140,font=40,code=pressKey"return", hide=hide_noRoom},