-
Notifications
You must be signed in to change notification settings - Fork 1
/
input.lua
119 lines (92 loc) · 3.18 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
-- BLAST FLOCK source files
-- by TRASEVOL_DOG (https://trasevol.dog/)
require("drawing")
input={}
input.btn_state= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
input.btn_press= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
input.btn_release= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
input.mosbtn_state= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
input.mosbtn_press= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
input.mosbtn_release= {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false}
function init_input_mgr()
input={}
input.btn_state={}
input.btn_press={}
input.btn_release={}
input.layout={
left=0,
right=1,
up=2,
down=3,
z=4,
x=5,
p=6,
escape=7,
["return"]=8,
v=9
}
input.btn_count=0
for _,_ in pairs(input.layout) do
input.btn_count = input.btn_count + 1
end
for i=0,input.btn_count-1 do
input.btn_state[i]=false
input.btn_press[i]=false
input.btn_release[i]=false
end
input.mosbtn_state={}
input.mosbtn_press={}
input.mosbtn_release={}
for i=0,2 do
input.mosbtn_state[i]=false
input.mosbtn_press[i]=false
input.mosbtn_release[i]=false
end
input.mosx,input.mosy=love.mouse.getPosition()
end
function btn(k) return input.btn_state[k] end
function btnp(k) return input.btn_press[k] end
function btnr(k) return input.btn_release[k] end
function mouse_pos() return input.mosx,input.mosy end
function mouse_btn(k) return input.mosbtn_state[k] end
function mouse_btnp(k) return input.mosbtn_press[k] end
function mouse_btnr(k) return input.mosbtn_release[k] end
function update_input_mgr()
for i=0,input.btn_count-1 do
input.btn_press[i]=false
input.btn_release[i]=false
end
for i=0,2 do
input.mosbtn_press[i]=false
input.mosbtn_release[i]=false
end
local omx,omy=input.mosx,input.mosy
input.mosx,input.mosy=love.mouse.getPosition()
input.mosx=input.mosx/graphics.scrn_scalex
input.mosy=input.mosy/graphics.scrn_scaley
input.mosx=input.mosx+0.5*(input.mosx-omx)
input.mosy=input.mosy+0.5*(input.mosy-omy)
end
function input_keypressed(key)
local k=input.layout[key]
if k then
input.btn_state[k]=true
input.btn_press[k]=true
end
menu_keypressed(key)
end
function input_keyreleased(key)
local k=input.layout[key]
if k then
input.btn_state[k]=false
input.btn_release[k]=true
end
end
function input_mousepressed(x,y,k,istouch)
input.mosbtn_state[k-1]=true
input.mosbtn_press[k-1]=true
end
function input_mousereleased(x,y,k,istouch)
input.mosbtn_state[k-1]=false
input.mosbtn_release[k-1]=true
end