diff options
author | Aki <nthirtyone@gmail.com> | 2017-04-05 19:45:59 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-04-05 19:45:59 +0200 |
commit | a46bdb0673461a69fe4467f794f0ddaab9449f85 (patch) | |
tree | 449481ea8000208a421534c294ecf8791081f9b7 | |
parent | 527901f599c79047ab9a12fbc065a93faa8f872e (diff) | |
download | roflnauts-a46bdb0673461a69fe4467f794f0ddaab9449f85.zip roflnauts-a46bdb0673461a69fe4467f794f0ddaab9449f85.tar.gz roflnauts-a46bdb0673461a69fe4467f794f0ddaab9449f85.tar.bz2 |
Hero no longer uses controler-related functions/methods
-rw-r--r-- | not/Hero.lua | 6 | ||||
-rw-r--r-- | not/Player.lua | 31 |
2 files changed, 17 insertions, 20 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 760a881..6d0a202 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -20,6 +20,7 @@ Hero = { inAir = true, salto = false, isJumping = false, + isWalking = false, jumpTimer = 0.16, jumpCounter = 2, -- Statics @@ -166,12 +167,9 @@ end -- Change animation of `Hero` -- default, walk, attack, attack_up, attack_down, damage function Hero:goToNextFrame () - local isDown = Controller.isDown - local controlset = self:getControlSet() if self.current.repeated or not (self.frame == self.current.frames) then self.frame = (self.frame % self.current.frames) + 1 - elseif isDown(controlset, "right") or isDown(controlset, "left") then - -- If nonrepeatable animation is finished and player is walking + elseif self.isWalking then self:setAnimation("walk") elseif self.current == self.animations.damage then self:setAnimation("default") diff --git a/not/Player.lua b/not/Player.lua index 2bee903..515684f 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -92,8 +92,6 @@ end -- Controller callbacks. function Player:controlpressed (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then if self.jumpCounter > 0 then @@ -122,24 +120,26 @@ function Player:controlpressed (set, action, key) end -- Walking - if (action == "left" or action == "right") and - (self.current ~= self.animations.attack) and - (self.current ~= self.animations.attack_up) and - (self.current ~= self.animations.attack_down) then - self:setAnimation("walk") + if (action == "left" or action == "right") then + self.isWalking = true + if (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end end -- Punching if action == "attack" and self.punchCooldown <= 0 then local f = self.facing self.salto = false - if isDown(controlset, "up") then + if self:isControlDown("up") then -- Punch up if self.current ~= self.animations.damage then self:setAnimation("attack_up") end self:punch("up") - elseif isDown(controlset, "down") then + elseif self:isControlDown("down") then -- Punch down if self.current ~= self.animations.damage then self:setAnimation("attack_down") @@ -161,18 +161,17 @@ function Player:controlpressed (set, action, key) end function Player:controlreleased (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then self.isJumping = false self.jumpTimer = Hero.jumpTimer -- take initial from metatable end -- Walking - if (action == "left" or action == "right") and not - (isDown(controlset, "left") or isDown(controlset, "right")) and - self.current == self.animations.walk - then - self:setAnimation("default") + if (action == "left" or action == "right") then + self.isWalking = false + if not (self:isControlDown("left") or self:isControlDown("right")) and + self.current == self.animations.walk then + self:setAnimation("default") + end end end |