-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.lua
More file actions
98 lines (88 loc) · 2.98 KB
/
Copy pathcontrols.lua
File metadata and controls
98 lines (88 loc) · 2.98 KB
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
local controls = {
bindings = {
-- aim controls
r_left = {'key:left', 'axis:rightx-'},
r_right = {'key:right', 'axis:rightx+'},
r_up = {'key:up', 'axis:righty-'},
r_down = {'key:down', 'axis:righty+'},
-- movement
dp_left = {'key:a', 'button:dpleft'},
dp_right = {'key:d', 'button:dpright'},
dp_up = {'key:w', 'button:dpup'},
dp_down = {'key:s', 'button:dpdown'},
-- buttons
a = {'key:g', 'button:a'},
x = {'key:r', 'button:x'},
y = {'key:t', 'button:y'},
r1 = {'mouse:1', 'button:rightshoulder'},
r2 = {'mouse:2'},
l1 = {'key:space', 'button:leftshoulder'},
menu = {'key:escape', 'button:start'},
view = {'key:q', 'button:back'},
}
}
function controls.setup()
controller = baton.new(controls.bindings) -- set controller.joystick to a Joystick later
controller.pairs = {dpad = {'dp_left', 'dp_right', 'dp_up', 'dp_down'}}
controller.deadzone = 0.2
return controller
end
local last_key_dir = { l = 0, r = 0, u = 0, d = 0 } -- left right up down
local doubletap_time = 0.2 -- time to double-tap
local aim_distance = 300
function controls.process(a)
a.controls.x, a.controls.y = 0, 0
if controller:down('dp_left') then a.controls.x = a.controls.x - 1 end
if controller:down('dp_right') then a.controls.x = a.controls.x + 1 end
if controller:down('dp_up') then a.controls.y = a.controls.y - 1 end
if controller:down('dp_down') then a.controls.y = a.controls.y + 1 end
if controller:pressed('dp_left') then
if (guitime - last_key_dir.l) < doubletap_time and not player:check_status("dash_cooldown") then
player:dash_left()
end
last_key_dir.l = guitime
end
if controller:pressed('dp_right') then
if (guitime - last_key_dir.r) < doubletap_time and not player:check_status("dash_cooldown") then
player:dash_right()
end
last_key_dir.r = guitime
end
a.controls.jump = controller:pressed('l1')
a.controls.float = controller:down('l1')
if controller:pressed('x') and a.weapon.ammo ~= a.weapon.ammo_max then
a.controls.reload = true
end
if controller:pressed('y') then
a.controls.swap_weapons = true
end
a.controls.fire_1 = controller:down('r1')
a.controls.fire_2 = controller:down('r2')
if controller:getActiveDevice() == "joystick" then
jx = controller:get('r_right') - controller:get('r_left')
jy = controller:get('r_down') - controller:get('r_up')
if jx == 0 and jy == 0 then
if a.facing == 'r' then
mouse = {x = player.x + aim_distance - camera.x,
y = player.y - camera.y}
else
mouse = {x = player.x - aim_distance - camera.x,
y = player.y - camera.y}
end
else
norm = math.sqrt(jx * jx + jy * jy)
mouse = {x = player.x + mymath.round(aim_distance * (jx / norm)) - camera.x,
y = player.y + mymath.round(aim_distance * (jy / norm)) - camera.y}
end
else
mouse = {x = love.mouse.getX(), y = love.mouse.getY()}
end
a.controls.aim_x, a.controls.aim_y = mouse.x + camera.x, mouse.y + camera.y
-- face the cursor
if a.controls.aim_x >= a.x then
a.facing = 'r'
else
a.facing = 'l'
end
end
return controls