summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--not/Hero.lua32
-rw-r--r--not/Player.lua16
2 files changed, 28 insertions, 20 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index 681d7e6..2e1f1f0 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -43,7 +43,6 @@ function Hero:new (config, x, y, world)
self.salto = false
self.smoke = false
self.isAlive = true
- self.isWalking = false
self.isJumping = false
self.spawntimer = 2
self.punchCooldown = 0
@@ -124,6 +123,13 @@ function Hero:update (dt)
end
end
+ if self:isWalkingLeft() then
+ self:walk(-1)
+ end
+ if self:isWalkingRight() then
+ self:walk(1)
+ end
+
-- Stop vertical
local currentAnimation = self:getAnimation()
if self.frame < currentAnimation.frames then
@@ -138,7 +144,7 @@ end
--- Damps linear velocity every frame by applying minor force to body.
function Hero:dampVelocity (dt)
- if not self.isWalking then
+ if not self:isWalking() then
local face
local x, y = self:getLinearVelocity()
if x < -12 then
@@ -199,7 +205,7 @@ end
function Hero:goToNextFrame ()
if self.current.repeated or not (self.frame == self.current.frames) then
self.frame = (self.frame % self.current.frames) + 1
- elseif self.isWalking then
+ elseif self:isWalking() then
self:setAnimation("walk")
elseif self.current == self.animations.damage then
self:setAnimation("default")
@@ -227,6 +233,18 @@ function Hero:land ()
self:createEffect("land")
end
+function Hero:isWalking ()
+ return self:isWalkingLeft() or self:isWalkingRight()
+end
+
+function Hero:isWalkingLeft ()
+ return false
+end
+
+function Hero:isWalkingRight ()
+ return false
+end
+
function Hero:walk (face)
local x, y = self:getLinearVelocity()
self.facing = face
@@ -239,14 +257,6 @@ function Hero:walk (face)
end
end
-function Hero:walkLeft ()
- self:walk(-1)
-end
-
-function Hero:walkRight ()
- self:walk(1)
-end
-
-- Creates temporary fixture for hero's body that acts as sensor.
-- direction: ("left", "right", "up", "down")
-- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`.
diff --git a/not/Player.lua b/not/Player.lua
index 6996c9d..0b56e6d 100644
--- a/not/Player.lua
+++ b/not/Player.lua
@@ -35,14 +35,14 @@ function Player:update (dt)
self:setLinearVelocity(x,-160)
self.jumpTimer = self.jumpTimer - dt
end
+end
- -- Walking.
- if self:isControlDown("left") then
- self:walkLeft()
- end
- if self:isControlDown("right") then
- self:walkRight()
- end
+function Player:isWalkingLeft ()
+ return self:isControlDown("left")
+end
+
+function Player:isWalkingRight ()
+ return self:isControlDown("right")
end
-- Controller callbacks.
@@ -78,7 +78,6 @@ function Player:controlpressed (set, action, key)
-- Walking
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
@@ -125,7 +124,6 @@ function Player:controlreleased (set, action, key)
-- Walking
if (action == "left" or action == "right") then
if not (self:isControlDown("left") or self:isControlDown("right")) then
- self.isWalking = false
if self.current == self.animations.walk then
self:setAnimation("default")
end