-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.lua
More file actions
48 lines (43 loc) · 734 Bytes
/
input.lua
File metadata and controls
48 lines (43 loc) · 734 Bytes
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
Input = Class('Input')
local keys = {
'up',
'down',
'left',
'right',
'a',
'b',
'start',
'select'
}
function Input:initialize(player)
self.player = player or 1
self.keys = {}
for i,v in ipairs(keys) do
self.keys[v] = 0
end
end
function Input:press(k,t)
t = t or 1
self.keys[k] = math.max(self.keys[k],t)
end
function Input:release(k)
self.keys[k] = 0
end
function Input:send()
local out = {}
for k,v in pairs(self.keys) do
local realKey = k
if #k == 1 then realKey = string.upper(k) end
if v ~= 0 then
self.keys[k] = math.max(0,v-1)
out[realKey] = true
else
if config.blockUserInput then
out[realKey] = false
else
out[realKey] = nil
end
end
end
joypad.set(self.player,out)
end