From d301a1c12b6e5cb3d0784cb2e8cccce5bd3d9069 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 9 Feb 2021 18:31:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E8=99=9A=E6=8B=9F=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 57 +++++++++++++++++++++++++++++++++++-- parts/scenes/net_game.lua | 55 ++++------------------------------- parts/scenes/play.lua | 60 ++++++--------------------------------- 3 files changed, 68 insertions(+), 104 deletions(-) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index 26e5db0a..6c24a272 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -363,7 +363,7 @@ end --Game draw local VK=virtualkey -function drawVirtualKeys() +function drawVirtualkeys() if SETTING.VKSwitch then local a=SETTING.VKAlpha local _ @@ -403,6 +403,57 @@ function drawVirtualKeys() end end end +function onVirtualkey(x,y) + local dist,nearest=1e10 + for K=1,#VK do + local B=VK[K] + if B.ava then + local d1=(x-B.x)^2+(y-B.y)^2 + if d10 then + b.x=b.x+(b.x-B.x)*d*b.r*5e-4 + b.y=b.y+(b.y-B.y)*d*b.r*5e-4 + end + end + end + local O=VK_org[t] + local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW + local _OW=1-_FW-_CW + + --Auto follow: finger, current, origin (weight from setting) + B.x,B.y=x*_FW+B.x*_CW+O.x*_OW,y*_FW+B.y*_CW+O.y*_OW + end + SFX.play("virtualKey",SETTING.VKSFX) + VIB(SETTING.VKVIB) +end +function updateVirtualkey() + if SETTING.VKSwitch then + for i=1,#VK do + _=VK[i] + if _.pressTime>0 then + _.pressTime=_.pressTime-1 + end + end + end +end + --Game @@ -478,7 +529,7 @@ function destroyPlayers()--Destroy all player objects, restore freerows and free end collectgarbage() end -function restoreVirtualKey() +function restoreVirtualkey() for i=1,#VK_org do local B,O=virtualkey[i],VK_org[i] B.ava=O.ava @@ -683,7 +734,7 @@ do--function resetGameData(args) destroyPlayers() GAME.curMode.load(playerData) initPlayerPosition(args:find("q")) - restoreVirtualKey() + restoreVirtualkey() if GAME.modeEnv.task then for i=1,#PLAYERS do PLAYERS[i]:newTask(GAME.modeEnv.task) diff --git a/parts/scenes/net_game.lua b/parts/scenes/net_game.lua index a630d396..c421db8a 100644 --- a/parts/scenes/net_game.lua +++ b/parts/scenes/net_game.lua @@ -8,21 +8,9 @@ local max,sin=math.max,math.sin local SCR=SCR local VK=virtualkey -local function onVirtualkey(x,y) - local dist,nearest=1e10 - for K=1,#VK do - local B=VK[K] - if B.ava then - local d1=(x-B.x)^2+(y-B.y)^2 - if d10 then - SFX.play("virtualKey",SETTING.VKSFX) - end - local B=VK[t] - B.isDown=true - B.pressTime=10 - if SETTING.VKTrack then - if SETTING.VKDodge then--Button collision (not accurate) - for i=1,#VK do - local b=VK[i] - local d=B.r+b.r-((B.x-b.x)^2+(B.y-b.y)^2)^.5--Hit depth(Neg means distance) - if d>0 then - b.x=b.x+(b.x-B.x)*d*b.r*5e-4 - b.y=b.y+(b.y-B.y)*d*b.r*5e-4 - end - end - end - local O=VK_org[t] - local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW - local _OW=1-_FW-_CW - - --Auto follow: finger, current, origin (weight from setting) - B.x,B.y=x*_FW+B.x*_CW+O.x*_OW,y*_FW+B.y*_CW+O.y*_OW - end - VIB(SETTING.VKVIB) + pressVirtualkey(t,x,y) end end function scene.touchUp(_,x,y) @@ -293,14 +257,7 @@ function scene.update(dt) touchMoveLastFrame=false --Update virtualkey animation - if SETTING.VKSwitch then - for i=1,#VK do - _=VK[i] - if _.pressTime>0 then - _.pressTime=_.pressTime-1 - end - end - end + updateVirtualkey() if not playing then heartBeatTimer=heartBeatTimer+dt @@ -393,7 +350,7 @@ function scene.draw() end --Virtual keys - drawVirtualKeys() + drawVirtualkeys() --Warning gc.push("transform") diff --git a/parts/scenes/play.lua b/parts/scenes/play.lua index 78b7450b..95e8e0e3 100644 --- a/parts/scenes/play.lua +++ b/parts/scenes/play.lua @@ -6,21 +6,9 @@ local max,sin=math.max,math.sin local SCR=SCR local VK=virtualkey -local function onVirtualkey(x,y) - local dist,nearest=1e10 - for K=1,#VK do - local B=VK[K] - if B.ava then - local d1=(x-B.x)^2+(y-B.y)^2 - if d10 then - SFX.play("virtualKey",SETTING.VKSFX) - end - local B=VK[t] - B.isDown=true - B.pressTime=10 - if SETTING.VKTrack then - if SETTING.VKDodge then--Button collision (not accurate) - for i=1,#VK do - local b=VK[i] - local d=B.r+b.r-((B.x-b.x)^2+(B.y-b.y)^2)^.5--Hit depth(Neg means distance) - if d>0 then - b.x=b.x+(b.x-B.x)*d*b.r*5e-4 - b.y=b.y+(b.y-B.y)*d*b.r*5e-4 - end - end - end - local O=VK_org[t] - local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW - local _OW=1-_FW-_CW - - --Auto follow: finger, current, origin (weight from setting) - B.x,B.y=x*_FW+B.x*_CW+O.x*_OW,y*_FW+B.y*_CW+O.y*_OW - end - VIB(SETTING.VKVIB) + pressVirtualkey(t,x,y) end end function scene.touchUp(_,x,y) @@ -168,14 +132,7 @@ function scene.update(dt) touchMoveLastFrame=false --Update virtualkey animation - if SETTING.VKSwitch then - for i=1,#VK do - _=VK[i] - if _.pressTime>0 then - _.pressTime=_.pressTime-1 - end - end - end + updateVirtualkey() --Replay if GAME.replaying then @@ -186,11 +143,10 @@ function scene.update(dt) if key==0 then--Just wait elseif key<=32 then--Press key P1:pressKey(key) - VK[key].isDown=true - VK[key].pressTime=10 + pressVirtualkey(key) elseif key<=64 then--Release key - VK[key-32].isDown=false P1:releaseKey(key-32) + VK[key-32].isDown=false end _=_+2 end @@ -284,7 +240,7 @@ function scene.draw() end --Virtual keys - drawVirtualKeys() + drawVirtualkeys() --Attacking & Being attacked if GAME.modeEnv.royaleMode then