summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-27 17:43:34 +0200
committerAki <nthirtyone@gmail.com>2016-05-27 17:43:34 +0200
commitf9d6f8e3a41835671da69f20702c0313bda96fe0 (patch)
tree3726d0da5be1c0d7a974a2ae9f4a17d5ece95e74
parent50fc48bf4e1de8382513da390eeece796f18926e (diff)
downloadroflnauts-f9d6f8e3a41835671da69f20702c0313bda96fe0.zip
roflnauts-f9d6f8e3a41835671da69f20702c0313bda96fe0.tar.gz
roflnauts-f9d6f8e3a41835671da69f20702c0313bda96fe0.tar.bz2
Controller
-rw-r--r--controller.lua6
-rw-r--r--player.lua15
2 files changed, 15 insertions, 6 deletions
diff --git a/controller.lua b/controller.lua
index d00f434..d6dcb6d 100644
--- a/controller.lua
+++ b/controller.lua
@@ -62,7 +62,7 @@ function Controller:keypressed(key, scancode)
if self.parent ~= nil and self.joystick == nil then
local control = self:testControl(key)
if control ~= nil then
- self.parent:controllerPressed(control)
+ self.parent:controllerPressed(control, self)
end
end
end
@@ -71,7 +71,7 @@ function Controller:keyreleased(key, scancode)
if self.parent ~= nil and self.joystick == nil then
local control = self:testControl(key)
if control ~= nil then
- self.parent:controllerReleased(control)
+ self.parent:controllerReleased(control, self)
end
end
end
@@ -80,6 +80,6 @@ function Controller:isDown(control)
if self.joystick == nil then
return love.keyboard.isDown(self[control])
else
- return self.joystick:isGamepadDown(self[control])
+ return self.joystick:isGamepadDown(self[control], self)
end
end \ No newline at end of file
diff --git a/player.lua b/player.lua
index 3e94221..d81ceb1 100644
--- a/player.lua
+++ b/player.lua
@@ -39,6 +39,7 @@ Player = {
jumptimer = 0.14,
-- Keys
controller = nil,
+ controller_empty = {isDown = function () return false end},
-- HUD
portrait_sprite = nil,
portrait_sheet = require "portraits"
@@ -78,6 +79,14 @@ function Player:assignController(controller)
controller:setParent(self)
end
+function Player:getController()
+ if self.controller ~= nil then
+ return self.controller
+ else
+ return self.controller_empty
+ end
+end
+
-- Update callback of `Player`
function Player:update (dt)
-- # VERTICAL MOVEMENT
@@ -98,7 +107,7 @@ function Player:update (dt)
-- # HORIZONTAL MOVEMENT
-- Walking
local x,y = self.body:getLinearVelocity()
- local controller = self.controller
+ local controller = self:getController()
if controller:isDown("left") then
self.facing = -1
self.body:applyForce(-250, 0)
@@ -189,7 +198,7 @@ end
-- Keypressed callback (I think?) of `Player`
function Player:controllerPressed (key)
- local controller = self.controller
+ local controller = self:getController()
-- Jumping
if key == "jump" then
if not self.inAir then
@@ -242,7 +251,7 @@ end
-- Keyreleased callback (I think?) of `Player`
function Player:controllerReleased (key)
- local controller = self.controller
+ local controller = self:getController()
-- Jumping
if key == "jump" then
self.jumpactive = false