整理代码

This commit is contained in:
MrZ626
2020-12-10 10:34:53 +08:00
parent 0439a3e73d
commit 106a22eb27

View File

@@ -24,6 +24,9 @@ local function onVirtualkey(x,y)
return nearest return nearest
end end
local noTouch
local noKey
local scene={} local scene={}
function scene.sceneInit() function scene.sceneInit()
@@ -33,10 +36,12 @@ function scene.sceneInit()
resetGameData() resetGameData()
GAME.init=nil GAME.init=nil
end end
noKey=GAME.replaying
noTouch=not SETTING.VKSwitch or noKey
end end
function scene.touchDown(_,x,y) function scene.touchDown(_,x,y)
if not SETTING.VKSwitch or GAME.replaying then return end if noTouch then return end
local t=onVirtualkey(x,y) local t=onVirtualkey(x,y)
if t then if t then
@@ -44,10 +49,10 @@ function scene.touchDown(_,x,y)
if SETTING.VKSFX>0 then if SETTING.VKSFX>0 then
SFX.play("virtualKey",SETTING.VKSFX) SFX.play("virtualKey",SETTING.VKSFX)
end end
VK[t].isDown=true local B=VK[t]
VK[t].pressTime=10 B.isDown=true
B.pressTime=10
if SETTING.VKTrack then if SETTING.VKTrack then
local B=VK[t]
if SETTING.VKDodge then--Button collision (not accurate) if SETTING.VKDodge then--Button collision (not accurate)
for i=1,#VK do for i=1,#VK do
local b=VK[i] local b=VK[i]
@@ -69,7 +74,7 @@ function scene.touchDown(_,x,y)
end end
end end
function scene.touchUp(_,x,y) function scene.touchUp(_,x,y)
if not SETTING.VKSwitch or GAME.replaying then return end if noTouch then return end
local t=onVirtualkey(x,y) local t=onVirtualkey(x,y)
if t then if t then
@@ -77,7 +82,7 @@ function scene.touchUp(_,x,y)
end end
end end
function scene.touchMove() function scene.touchMove()
if not SETTING.VKSwitch or GAME.replaying then return end if noTouch then return end
local l=tc.getTouches() local l=tc.getTouches()
for n=1,#VK do for n=1,#VK do
@@ -93,7 +98,7 @@ function scene.touchMove()
end end
end end
function scene.keyDown(key) function scene.keyDown(key)
if not GAME.replaying then if not noKey then
local m=keyMap local m=keyMap
for k=1,20 do for k=1,20 do
if key==m[1][k]or key==m[2][k]then if key==m[1][k]or key==m[2][k]then
@@ -107,7 +112,7 @@ function scene.keyDown(key)
if key=="escape"then pauseGame()end if key=="escape"then pauseGame()end
end end
function scene.keyUp(key) function scene.keyUp(key)
if GAME.replaying then return end if noKey then return end
local m=keyMap local m=keyMap
for k=1,20 do for k=1,20 do
if key==m[1][k]or key==m[2][k]then if key==m[1][k]or key==m[2][k]then
@@ -118,7 +123,7 @@ function scene.keyUp(key)
end end
end end
function scene.gamepadDown(key) function scene.gamepadDown(key)
if GAME.replaying then return end if noKey then return end
local m=keyMap local m=keyMap
for k=1,20 do for k=1,20 do
@@ -133,7 +138,7 @@ function scene.gamepadDown(key)
if key=="back"then pauseGame()end if key=="back"then pauseGame()end
end end
function scene.gamepadUp(key) function scene.gamepadUp(key)
if GAME.replaying then return end if noKey then return end
local m=keyMap local m=keyMap
for k=1,20 do for k=1,20 do
@@ -353,9 +358,8 @@ function scene.draw()
end end
gc.pop() gc.pop()
end end
scene.widgetList={ scene.widgetList={
WIDGET.newButton{name="pause",x=1235,y=45,w=80,font=25,code=function()pauseGame()end}, WIDGET.newKey{name="pause",x=1235,y=45,w=80,font=25,code=function()pauseGame()end},
} }
return scene return scene