-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.lua
85 lines (63 loc) · 1.92 KB
/
input.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
tactile = require "tactile/tactile"
input = {}
local PLAYER_ONE = 1
local horizontal, vertical
local jump, reset, start
local startWasDown = false
local startPressed = false
local startTimeout = 1
local lastStartPress = -math.huge
function input.load()
upKey = tactile.key("up")
downKey = tactile.key("down")
leftKey = tactile.key("left")
rightKey = tactile.key("right")
wKey = tactile.key('w')
aKey = tactile.key('a')
sKey = tactile.key('s')
dKey = tactile.key('d')
keyboardXAxis = tactile.binaryAxis(leftKey, rightKey)
keyboardYAxis = tactile.binaryAxis(upKey, downKey)
wasdXAxis = tactile.binaryAxis(aKey, dKey)
wasdYAxis = tactile.binaryAxis(wKey, sKey)
gamepadXAxis = tactile.analogStick('leftx', PLAYER_ONE)
gamepadYAxis = tactile.analogStick('lefty', PLAYER_ONE)
horizontal = tactile.newAxis(keyboardXAxis, wasdXAxis, gamepadXAxis)
vertical = tactile.newAxis(keyboardYAxis, wasdYAxis, gamepadYAxis)
keyboardJump = tactile.key(' ')
gamepadJump = tactile.gamepadButton('a', PLAYER_ONE)
jump = tactile.newButton(keyboardJump, gamepadJump)
keyboardReset = tactile.key('r')
gamepadReset = tactile.gamepadButton('y', PLAYER_ONE)
reset = tactile.newButton(keyboardReset, gamepadReset)
keyboardStart = tactile.key('escape')
gamepadStart = tactile.gamepadButton('start', PLAYER_ONE)
start = tactile.newButton(keyboardStart, gamepadStart)
end
function input.update()
jump:update()
reset:update()
start:update()
-- tactile bug ?
if start:isDown() and not startWasDown then
startPressed = true
else
startPressed = false
end
startWasDown = start:isDown()
end
function input.getStartPressed()
return startPressed
end
function input.getReset()
return reset:isDown()
end
function input.getJump()
return jump:isDown()
end
function input.getXAxis()
return horizontal:getValue()
end
function input.getYAxis()
return vertical:getValue()
end