summaryrefslogtreecommitdiffhomepage
path: root/controller.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-06-04 16:27:30 +0200
committerAki <nthirtyone@gmail.com>2016-06-04 16:27:30 +0200
commit76361a11953a68f807275fd456667c7dcf0cbc97 (patch)
tree867b536f78ec4eeb2fdb5ac3b854c2968b6cda41 /controller.lua
parent3787499248fdc2d2b881b20779911733eb2678ad (diff)
downloadroflnauts-76361a11953a68f807275fd456667c7dcf0cbc97.zip
roflnauts-76361a11953a68f807275fd456667c7dcf0cbc97.tar.gz
roflnauts-76361a11953a68f807275fd456667c7dcf0cbc97.tar.bz2
Gamepad support \o/
Diffstat (limited to 'controller.lua')
-rw-r--r--controller.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/controller.lua b/controller.lua
index d6dcb6d..c52b4a8 100644
--- a/controller.lua
+++ b/controller.lua
@@ -58,6 +58,26 @@ function Controller:testControl(control)
end
end
+-- Gamepad
+function Controller:gamepadpressed(joystick, button)
+ if self.parent ~= nil and self.joystick == joystick then
+ local control = self:testControl(button)
+ if control ~= nil then
+ self.parent:controllerPressed(control, self)
+ end
+ end
+end
+
+function Controller:gamepadreleased(joystick, button)
+ if self.parent ~= nil and self.joystick == joystick then
+ local control = self:testControl(button)
+ if control ~= nil then
+ self.parent:controllerReleased(control, self)
+ end
+ end
+end
+
+-- Keyboard
function Controller:keypressed(key, scancode)
if self.parent ~= nil and self.joystick == nil then
local control = self:testControl(key)
@@ -76,10 +96,11 @@ function Controller:keyreleased(key, scancode)
end
end
+-- isDown
function Controller:isDown(control)
if self.joystick == nil then
return love.keyboard.isDown(self[control])
else
- return self.joystick:isGamepadDown(self[control], self)
+ return self.joystick:isGamepadDown(self[control])
end
end \ No newline at end of file