diff options
-rw-r--r-- | controller.lua | 6 | ||||
-rw-r--r-- | player.lua | 15 |
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 @@ -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 |