-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.lua
93 lines (79 loc) · 2.07 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
85
86
87
88
89
90
91
92
--[[
Squaricles
Copyright (C) 2017 ITR
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
]]--
require ".helperfunctions"
UP = 1
DOWN = 2
LEFT = 3
RIGHT = 4
A = 5
B = 6
START = 7
Input = {queue = {}, keys = {}}
function love.keypressed( key, scancode, isrepeat)
if isrepeat then return end
for i=1,#Inputs do
local keys = Inputs[i].keys
for j=1,#keys do
if keys[j]==key then
Inputs[i].queue[#Inputs[i].queue+1] = j
end
end
end
end
function Input:useInput(func)
if func ~= nil then
for i=1,#self.queue do
success = func(self.queue[i]) or success
end
end
for i in pairs(self.queue) do self.queue[i] = nil end
end
function Input:isDown(key)
for i=1,#Inputs do
if Inputs[i].queue == self.queue then
if love.keyboard.isDown(Inputs[i].keys[key]) then
return true
end
end
end
return false
end
QWEASD = clone(Input)
QWEASD.keys[UP] = "w"
QWEASD.keys[DOWN] = "s"
QWEASD.keys[LEFT] = "a"
QWEASD.keys[RIGHT] = "d"
QWEASD.keys[A] = "q"
QWEASD.keys[B] = "e"
QWEASD.keys[START] = "space"
ARROWS = clone(Input)
ARROWS.queue = QWEASD.queue
ARROWS.keys[UP] = "up"
ARROWS.keys[DOWN] = "down"
ARROWS.keys[LEFT] = "left"
ARROWS.keys[RIGHT] = "right"
ARROWS.keys[A] = "rshift"
ARROWS.keys[B] = "rctrl"
ARROWS.keys[START] = "return"
UIOJKL = clone(Input)
UIOJKL.queue = ARROWS.queue
UIOJKL.keys[UP] = "i"
UIOJKL.keys[DOWN] = "k"
UIOJKL.keys[LEFT] = "j"
UIOJKL.keys[RIGHT] = "l"
UIOJKL.keys[A] = "u"
UIOJKL.keys[B] = "o"
UIOJKL.keys[START] = "p"
Inputs = {QWEASD, ARROWS, UIOJKL}