-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
76 lines (72 loc) · 1.75 KB
/
Copy pathcontrol.lua
File metadata and controls
76 lines (72 loc) · 1.75 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
local Control = {}
Control.new = function(self,side,joystick)
local _rsc = {}
setmetatable(_rsc,{__index = self})
_rsc.side = side
_rsc.joystick = joystick
return _rsc
end
Control.getControl = function(self)
local deadzone = 0.15
local _control = {}
_control.x = 0
_control.y = 0
if self.joystick ~= nil then
_control.x = self.joystick:getGamepadAxis(self.side.."x")
_control.y = self.joystick:getGamepadAxis(self.side.."y")
local magnitude = math.sqrt(_control.x*_control.x + _control.y*_control.y)
--_control.x = _control.x*math.abs(_control.x)
--_control.y = _control.y*math.abs(_control.y)
if magnitude < deadzone then
_control.x = 0
_control.y = 0
else
_control.x = (_control.x/magnitude)*((magnitude-deadzone)/(1-deadzone))
_control.y = (_control.y/magnitude)*((magnitude-deadzone)/(1-deadzone))
end
end
if self.side == "right" then
if love.keyboard.isDown("left") then
_control.x = -1
elseif love.keyboard.isDown("right") then
_control.x = 1
end
if love.keyboard.isDown("up") then
_control.y = -1
elseif love.keyboard.isDown("down") then
_control.y = 1
end
elseif self.side == "left" then
if love.keyboard.isDown("a") then
_control.x = -1
elseif love.keyboard.isDown("d") then
_control.x = 1
end
if love.keyboard.isDown("w") then
_control.y = -1
elseif love.keyboard.isDown("s") then
_control.y = 1
end
end
return _control
end
Control.getTrigger = function(self)
if self.joystick ~= nil then
return self.joystick:getGamepadAxis( "trigger"..self.side )
else
if self.side == "right" then
if love.keyboard.isDown(" ") then
return 1
else
return 0
end
else
if love.keyboard.isDown("tab") then
return 1
else
return 0
end
end
end
end
return Control