继续完善手柄控制
This commit is contained in:
@@ -154,7 +154,7 @@ local function _triggerMouseDown(x,y,k)
|
|||||||
lastX,lastY=x,y
|
lastX,lastY=x,y
|
||||||
if SETTING.clickFX then SYSFX.newTap(3,x,y)end
|
if SETTING.clickFX then SYSFX.newTap(3,x,y)end
|
||||||
end
|
end
|
||||||
local function _mouse_update(dt)
|
local function mouse_update(dt)
|
||||||
if not KBisDown('lctrl','rctrl')and KBisDown('up','down','left','right')then
|
if not KBisDown('lctrl','rctrl')and KBisDown('up','down','left','right')then
|
||||||
local dx,dy=0,0
|
local dx,dy=0,0
|
||||||
if KBisDown('up')then dy=dy-cursorSpd end
|
if KBisDown('up')then dy=dy-cursorSpd end
|
||||||
@@ -173,6 +173,26 @@ local function _mouse_update(dt)
|
|||||||
cursorSpd=6
|
cursorSpd=6
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local function gp_update(js,dt)
|
||||||
|
local sx,sy=js._jsObj:getGamepadAxis('leftx'),js._jsObj:getGamepadAxis('lefty')
|
||||||
|
if math.abs(sx)>.1 or math.abs(sy)>.1 then
|
||||||
|
local dx,dy=0,0
|
||||||
|
if sy<-.1 then dy=dy+2*sy*cursorSpd end
|
||||||
|
if sy>.1 then dy=dy+2*sy*cursorSpd end
|
||||||
|
if sx<-.1 then dx=dx+2*sx*cursorSpd end
|
||||||
|
if sx>.1 then dx=dx+2*sx*cursorSpd end
|
||||||
|
mx=max(min(mx+dx,1280),0)
|
||||||
|
my=max(min(my+dy,720),0)
|
||||||
|
if my==0 or my==720 then
|
||||||
|
WIDGET.sel=false
|
||||||
|
WIDGET.drag(0,0,0,-dy)
|
||||||
|
end
|
||||||
|
_updateMousePos(mx,my,dx,dy)
|
||||||
|
cursorSpd=min(cursorSpd+dt*26,12.6)
|
||||||
|
else
|
||||||
|
cursorSpd=6
|
||||||
|
end
|
||||||
|
end
|
||||||
function love.mousepressed(x,y,k,touch)
|
function love.mousepressed(x,y,k,touch)
|
||||||
if touch then return end
|
if touch then return end
|
||||||
mouseShow=true
|
mouseShow=true
|
||||||
@@ -347,35 +367,38 @@ local dPadToKey={
|
|||||||
back='escape',
|
back='escape',
|
||||||
}
|
}
|
||||||
function love.joystickadded(JS)
|
function love.joystickadded(JS)
|
||||||
jsState[JS:getID()]={
|
table.insert(jsState,{
|
||||||
_loveJSObj=JS,
|
_id=JS:getID(),
|
||||||
|
_jsObj=JS,
|
||||||
leftx=0,lefty=0,
|
leftx=0,lefty=0,
|
||||||
rightx=0,righty=0,
|
rightx=0,righty=0,
|
||||||
triggerleft=0,triggerright=0
|
triggerleft=0,triggerright=0
|
||||||
}
|
})
|
||||||
MES.new('info',"Joystick added")
|
MES.new('info',"Joystick added")
|
||||||
end
|
end
|
||||||
function love.joystickremoved(JS)
|
function love.joystickremoved(JS)
|
||||||
local js=jsState[JS:getID()]
|
for i=1,#jsState do
|
||||||
if js then
|
if jsState[i]._jsObj==JS then
|
||||||
for i=1,#gamePadKeys do
|
for j=1,#gamePadKeys do
|
||||||
if JS:isGamepadDown(gamePadKeys[i])then
|
if JS:isGamepadDown(gamePadKeys[j])then
|
||||||
love.gamepadreleased(JS,gamePadKeys[i])
|
love.gamepadreleased(JS,gamePadKeys[j])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
love.gamepadaxis(JS,'leftx',0)
|
||||||
|
love.gamepadaxis(JS,'lefty',0)
|
||||||
|
love.gamepadaxis(JS,'rightx',0)
|
||||||
|
love.gamepadaxis(JS,'righty',0)
|
||||||
|
love.gamepadaxis(JS,'triggerleft',-1)
|
||||||
|
love.gamepadaxis(JS,'triggerright',-1)
|
||||||
|
MES.new('info',"Joystick removed")
|
||||||
|
table.remove(jsState,i)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
love.gamepadaxis(JS,'leftx',0)
|
|
||||||
love.gamepadaxis(JS,'lefty',0)
|
|
||||||
love.gamepadaxis(JS,'rightx',0)
|
|
||||||
love.gamepadaxis(JS,'righty',0)
|
|
||||||
love.gamepadaxis(JS,'triggerleft',-1)
|
|
||||||
love.gamepadaxis(JS,'triggerright',-1)
|
|
||||||
jsState[JS:getID()]=nil
|
|
||||||
MES.new('info',"Joystick removed")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function love.gamepadaxis(JS,axis,val)
|
function love.gamepadaxis(JS,axis,val)
|
||||||
local js=jsState[JS:getID()]
|
if JS==jsState[1]._jsObj then
|
||||||
if js then
|
local js=jsState[1]
|
||||||
if axis=='leftx'or axis=='lefty'or axis=='rightx'or axis=='righty'then
|
if axis=='leftx'or axis=='lefty'or axis=='rightx'or axis=='righty'then
|
||||||
local newVal=--range: [0,1]
|
local newVal=--range: [0,1]
|
||||||
val>.4 and 1 or
|
val>.4 and 1 or
|
||||||
@@ -661,7 +684,8 @@ function love.run()
|
|||||||
|
|
||||||
--UPDATE
|
--UPDATE
|
||||||
STEP()
|
STEP()
|
||||||
if mouseShow then _mouse_update(dt)end
|
if mouseShow then mouse_update(dt)end
|
||||||
|
if next(jsState)then gp_update(jsState[1],dt)end
|
||||||
VOC_update()
|
VOC_update()
|
||||||
BG_update(dt)
|
BG_update(dt)
|
||||||
TEXT_update(dt)
|
TEXT_update(dt)
|
||||||
|
|||||||
@@ -162,11 +162,16 @@ function scene.update()
|
|||||||
if kb.isDown('down', 's')then dy=dy-10 F=true end
|
if kb.isDown('down', 's')then dy=dy-10 F=true end
|
||||||
if kb.isDown('left', 'a')then dx=dx+10 F=true end
|
if kb.isDown('left', 'a')then dx=dx+10 F=true end
|
||||||
if kb.isDown('right','d')then dx=dx-10 F=true end
|
if kb.isDown('right','d')then dx=dx-10 F=true end
|
||||||
local js1=Z.js[1]
|
local js=Z.js[1]
|
||||||
if js1 and js1.getGamepadAxis then
|
if js then
|
||||||
dx=dx+12.6*js1:getGamepadAxis('leftx')
|
local sx,sy=js._jsObj:getGamepadAxis('leftx'),js._jsObj:getGamepadAxis('lefty')
|
||||||
dy=dy+12.6*js1:getGamepadAxis('lefty')
|
if math.abs(sx)>.1 or math.abs(sy)>.1 then
|
||||||
F=true
|
if sy<-.1 then dy=dy-12.6*sy end
|
||||||
|
if sy>.1 then dy=dy-12.6*sy end
|
||||||
|
if sx<-.1 then dx=dx-12.6*sx end
|
||||||
|
if sx>.1 then dx=dx-12.6*sx end
|
||||||
|
F=true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if F then
|
if F then
|
||||||
|
|||||||
Reference in New Issue
Block a user