新增virtualKey模块整理虚拟按键相关代码,整理代码
This commit is contained in:
@@ -5,10 +5,7 @@ local tc=love.touch
|
||||
local sin=math.sin
|
||||
|
||||
local SCR=SCR
|
||||
local VK=virtualkey
|
||||
local onVirtualkey=onVirtualkey
|
||||
local pressVirtualkey=pressVirtualkey
|
||||
local updateVirtualkey=updateVirtualkey
|
||||
local VK=VK
|
||||
|
||||
local noTouch,noKey=false,false
|
||||
local touchMoveLastFrame=false
|
||||
@@ -34,16 +31,16 @@ end
|
||||
function scene.touchDown(x,y)
|
||||
if noTouch then return end
|
||||
|
||||
local t=onVirtualkey(x,y)
|
||||
local t=VK.on(x,y)
|
||||
if t then
|
||||
PLAYERS[1]:pressKey(t)
|
||||
pressVirtualkey(t,x,y)
|
||||
VK.touch(t,x,y)
|
||||
end
|
||||
end
|
||||
function scene.touchUp(x,y)
|
||||
if noTouch then return end
|
||||
|
||||
local t=onVirtualkey(x,y)
|
||||
local t=VK.on(x,y)
|
||||
if t then
|
||||
PLAYERS[1]:releaseKey(t)
|
||||
end
|
||||
@@ -56,8 +53,9 @@ function scene.touchMove()
|
||||
for i=#L,1,-1 do
|
||||
L[2*i-1],L[2*i]=SCR.xOy:inverseTransformPoint(tc.getPosition(L[i]))
|
||||
end
|
||||
for n=1,#VK do
|
||||
local B=VK[n]
|
||||
local keys=VK.getKeys
|
||||
for n=1,#keys do
|
||||
local B=keys[n]
|
||||
if B.ava then
|
||||
for i=1,#L,2 do
|
||||
if(L[i]-B.x)^2+(L[i+1]-B.y)^2<=B.r^2 then
|
||||
@@ -75,8 +73,9 @@ function scene.keyDown(key)
|
||||
if k>0 then
|
||||
if noKey then return end
|
||||
PLAYERS[1]:pressKey(k)
|
||||
VK[k].isDown=true
|
||||
VK[k].pressTime=10
|
||||
local vk=VK.getKeys()[k]
|
||||
vk.isDown=true
|
||||
vk.pressTime=10
|
||||
else
|
||||
restart()
|
||||
end
|
||||
@@ -90,7 +89,7 @@ function scene.keyUp(key)
|
||||
if k then
|
||||
if k>0 then
|
||||
PLAYERS[1]:releaseKey(k)
|
||||
VK[k].isDown=false
|
||||
VK.release(k)
|
||||
end
|
||||
elseif key=="back"then
|
||||
pauseGame()
|
||||
@@ -102,8 +101,7 @@ function scene.gamepadDown(key)
|
||||
if k then
|
||||
if k>0 then
|
||||
PLAYERS[1]:pressKey(k)
|
||||
VK[k].isDown=true
|
||||
VK[k].pressTime=10
|
||||
VK.press(k)
|
||||
else
|
||||
restart()
|
||||
end
|
||||
@@ -117,7 +115,7 @@ function scene.gamepadUp(key)
|
||||
if k then
|
||||
if k>0 then
|
||||
PLAYERS[1]:releaseKey(k)
|
||||
VK[k].isDown=false
|
||||
VK.release(k)
|
||||
end
|
||||
elseif key=="back"then
|
||||
pauseGame()
|
||||
@@ -138,10 +136,10 @@ function scene.update(dt)
|
||||
if key==0 then--Just wait
|
||||
elseif key<=32 then--Press key
|
||||
P1:pressKey(key)
|
||||
pressVirtualkey(key)
|
||||
VK.press(key)
|
||||
elseif key<=64 then--Release key
|
||||
P1:releaseKey(key-32)
|
||||
VK[key-32].isDown=false
|
||||
VK.release(key-32)
|
||||
end
|
||||
_=_+2
|
||||
end
|
||||
@@ -149,7 +147,7 @@ function scene.update(dt)
|
||||
end
|
||||
|
||||
touchMoveLastFrame=false
|
||||
updateVirtualkey()
|
||||
VK.update()
|
||||
|
||||
--Update players
|
||||
for p=1,#PLAYERS do PLAYERS[p]:update(dt)end
|
||||
@@ -183,7 +181,7 @@ function scene.draw()
|
||||
end
|
||||
|
||||
--Virtual keys
|
||||
drawVirtualkeys()
|
||||
VK.draw()
|
||||
|
||||
--Attacking & Being attacked
|
||||
if GAME.modeEnv.royaleMode then
|
||||
|
||||
@@ -4,10 +4,7 @@ local tc=love.touch
|
||||
local ins=table.insert
|
||||
|
||||
local SCR=SCR
|
||||
local VK=virtualkey
|
||||
local onVirtualkey=onVirtualkey
|
||||
local pressVirtualkey=pressVirtualkey
|
||||
local updateVirtualkey=updateVirtualkey
|
||||
local VK=VK
|
||||
|
||||
local textBox=WIDGET.newTextBox{name="texts",x=340,y=80,w=600,h=550,hide=false}
|
||||
|
||||
@@ -38,16 +35,16 @@ scene.mouseDown=NULL
|
||||
function scene.touchDown(x,y)
|
||||
if noTouch or not playing then return end
|
||||
|
||||
local t=onVirtualkey(x,y)
|
||||
local t=VK.on(x,y)
|
||||
if t then
|
||||
PLAYERS[1]:pressKey(t)
|
||||
pressVirtualkey(t,x,y)
|
||||
VK.touch(t,x,y)
|
||||
end
|
||||
end
|
||||
function scene.touchUp(x,y)
|
||||
if noTouch or not playing then return end
|
||||
|
||||
local t=onVirtualkey(x,y)
|
||||
local t=VK.on(x,y)
|
||||
if t then
|
||||
PLAYERS[1]:releaseKey(t)
|
||||
end
|
||||
@@ -60,8 +57,9 @@ function scene.touchMove()
|
||||
for i=#L,1,-1 do
|
||||
L[2*i-1],L[2*i]=SCR.xOy:inverseTransformPoint(tc.getPosition(L[i]))
|
||||
end
|
||||
for n=1,#VK do
|
||||
local B=VK[n]
|
||||
local keys=VK.getKeys
|
||||
for n=1,#keys do
|
||||
local B=keys[n]
|
||||
if B.ava then
|
||||
for i=1,#L,2 do
|
||||
if(L[i]-B.x)^2+(L[i+1]-B.y)^2<=B.r^2 then
|
||||
@@ -88,8 +86,9 @@ function scene.keyDown(key)
|
||||
local k=keyMap.keyboard[key]
|
||||
if k and k>0 then
|
||||
PLAYERS[1]:pressKey(k)
|
||||
VK[k].isDown=true
|
||||
VK[k].pressTime=10
|
||||
local vk=VK.getKeys()[k]
|
||||
vk.isDown=true
|
||||
vk.pressTime=10
|
||||
end
|
||||
elseif key=="space"then
|
||||
NET.signal_ready(not PLY_NET[1].ready)
|
||||
@@ -100,7 +99,7 @@ function scene.keyUp(key)
|
||||
local k=keyMap.keyboard[key]
|
||||
if k and k>0 then
|
||||
PLAYERS[1]:releaseKey(k)
|
||||
VK[k].isDown=false
|
||||
VK.release(k)
|
||||
end
|
||||
end
|
||||
function scene.gamepadDown(key)
|
||||
@@ -116,8 +115,7 @@ function scene.gamepadDown(key)
|
||||
local k=keyMap.joystick[key]
|
||||
if k and k>0 then
|
||||
PLAYERS[1]:pressKey(k)
|
||||
VK[k].isDown=true
|
||||
VK[k].pressTime=10
|
||||
VK.press(k)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -126,7 +124,7 @@ function scene.gamepadUp(key)
|
||||
local k=keyMap.joystick[key]
|
||||
if k and k>0 then
|
||||
PLAYERS[1]:releaseKey(k)
|
||||
VK[k].isDown=false
|
||||
VK.release(k)
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -185,7 +183,7 @@ function scene.socketRead(cmd,d)
|
||||
if P.uid==d.uid then
|
||||
local res,stream=pcall(love.data.decode,"string","base64",d.stream)
|
||||
if res then
|
||||
pumpRecording(stream,P.stream)
|
||||
DATA.pumpRecording(stream,P.stream)
|
||||
else
|
||||
LOG.print("Bad stream from "..P.username.."#"..P.uid)
|
||||
end
|
||||
@@ -203,7 +201,7 @@ function scene.update(dt)
|
||||
local GAME=GAME
|
||||
|
||||
touchMoveLastFrame=false
|
||||
updateVirtualkey()
|
||||
VK.update()
|
||||
|
||||
--Update players
|
||||
for p=1,#PLAYERS do PLAYERS[p]:update(dt)end
|
||||
@@ -214,7 +212,7 @@ function scene.update(dt)
|
||||
--Upload stream
|
||||
if P1.frameRun-lastUpstreamTime>8 then
|
||||
local stream
|
||||
stream,upstreamProgress=dumpRecording(GAME.rep,upstreamProgress)
|
||||
stream,upstreamProgress=DATA.dumpRecording(GAME.rep,upstreamProgress)
|
||||
if #stream>0 then
|
||||
NET.uploadRecStream(stream)
|
||||
else
|
||||
@@ -235,7 +233,7 @@ function scene.draw()
|
||||
end
|
||||
|
||||
--Virtual keys
|
||||
drawVirtualkeys()
|
||||
VK.draw()
|
||||
|
||||
--Warning
|
||||
drawWarning()
|
||||
|
||||
@@ -143,8 +143,10 @@ function scene.keyDown(key)
|
||||
SCN.swapTo("game","none")
|
||||
end
|
||||
elseif key=="o"then
|
||||
if(GAME.result or GAME.replaying)and #PLAYERS==1 and not GAME.saved and saveRecording()then
|
||||
GAME.saved=true
|
||||
if(GAME.result or GAME.replaying)and #PLAYERS==1 and not GAME.saved then
|
||||
if DATA.saveRecording()then
|
||||
GAME.saved=true
|
||||
end
|
||||
end
|
||||
else
|
||||
WIDGET.keyPressed(key)
|
||||
|
||||
@@ -51,8 +51,7 @@ end
|
||||
function scene.touchUp()
|
||||
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
|
||||
B.x,B.y=int(B.x/snapUnit+.5)*snapUnit,int(B.y/snapUnit+.5)*snapUnit
|
||||
end
|
||||
end
|
||||
function scene.touchMove(_,_,dx,dy)
|
||||
@@ -62,41 +61,19 @@ function scene.touchMove(_,_,dx,dy)
|
||||
end
|
||||
end
|
||||
|
||||
local function virtualkeyPreview()
|
||||
if SETTING.VKSwitch then
|
||||
for i=1,#VK_org do
|
||||
local B=VK_org[i]
|
||||
if B.ava then
|
||||
gc.setColor(1,1,1,SETTING.VKAlpha)
|
||||
gc.setLineWidth(B.r*.07)
|
||||
gc.circle("line",B.x,B.y,B.r,10)
|
||||
if selected==i and TIME()%.26<.13 then
|
||||
gc.setColor(1,1,1,SETTING.VKAlpha*.62)
|
||||
gc.circle("fill",B.x,B.y,B.r,10)
|
||||
end
|
||||
if SETTING.VKIcon then
|
||||
local c=B.color
|
||||
gc.setColor(c[1],c[2],c[3],SETTING.VKAlpha)
|
||||
gc.draw(TEXTURE.VKIcon[i],B.x,B.y,nil,B.r*.025,nil,18,18)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
function scene.draw()
|
||||
gc.setColor(1,1,1)
|
||||
gc.setLineWidth(7)gc.rectangle("line",340,15,600,690)
|
||||
gc.setLineWidth(3)gc.rectangle("line",490,85,300,600)
|
||||
virtualkeyPreview()
|
||||
local d=snapUnit
|
||||
if d>=10 then
|
||||
VK.preview(selected)
|
||||
if snapUnit>=10 then
|
||||
gc.setLineWidth(3)
|
||||
gc.setColor(1,1,1,sin(TIME()*4)*.1+.1)
|
||||
for i=1,1280/d-1 do
|
||||
gc.line(d*i,0,d*i,720)
|
||||
for i=1,1280/snapUnit-1 do
|
||||
gc.line(snapUnit*i,0,snapUnit*i,720)
|
||||
end
|
||||
for i=1,720/d-1 do
|
||||
gc.line(0,d*i,1280,d*i)
|
||||
for i=1,720/snapUnit-1 do
|
||||
gc.line(0,snapUnit*i,1280,snapUnit*i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user