整理虚拟按键碰撞相关代码,调整碰撞力度

This commit is contained in:
MrZ626
2021-02-21 21:44:46 +08:00
parent eb79aad6cd
commit f70099352a
2 changed files with 22 additions and 23 deletions

View File

@@ -420,26 +420,30 @@ function onVirtualkey(x,y)
return nearest
end
function pressVirtualkey(t,x,y)
local SETTING=SETTING
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
--Auto follow
local O=VK_org[t]
local _FW,_CW=SETTING.VKTchW,1-SETTING.VKCurW
local _OW=1-_FW-_CW
--(finger+current+origin)
B.x=x*_FW+B.x*_CW+O.x*_OW
B.y=y*_FW+B.y*_CW+O.y*_OW
--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
--Button collision (not accurate)
if SETTING.VKDodge then
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*6.2e-5
b.y=b.y+(b.y-B.y)*d*b.r*6.2e-5
end
end
end
end
SFX.play("virtualKey",SETTING.VKSFX)
VIB(SETTING.VKVIB)

View File

@@ -35,19 +35,14 @@ local function onVK_org(x,y)
end
function scene.mouseDown(x,y,k)
if k==2 then SCN.back()end
selected=onVK_org(x,y)or selected
end
function scene.mouseMove(_,_,dx,dy)
if selected and ms.isDown(1)and not WIDGET.sel then
local B=VK_org[selected]
B.x,B.y=B.x+dx,B.y+dy
end
scene.touchDown(x,y)
end
function scene.mouseUp()
if selected then
local B=VK_org[selected]
local k=snapUnit
B.x,B.y=int(B.x/k+.5)*k,int(B.y/k+.5)*k
scene.touchUp()
end
function scene.mouseMove(_,_,dx,dy)
if ms.isDown(1)then
scene.touchMove(nil,nil,dx,dy)
end
end
function scene.touchDown(x,y)