summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
Diffstat (limited to 'not')
-rw-r--r--not/Hero.lua20
-rw-r--r--not/Player.lua14
2 files changed, 22 insertions, 12 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index a97a2b1..681d7e6 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -227,6 +227,26 @@ function Hero:land ()
self:createEffect("land")
end
+function Hero:walk (face)
+ local x, y = self:getLinearVelocity()
+ self.facing = face
+ self:applyForce(250 * face, 0)
+ if x > self.MAX_VELOCITY then
+ self:applyForce(-250, 0)
+ end
+ if x < -self.MAX_VELOCITY then
+ self:applyForce(250, 0)
+ 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 b0dac75..6996c9d 100644
--- a/not/Player.lua
+++ b/not/Player.lua
@@ -38,20 +38,10 @@ function Player:update (dt)
-- Walking.
if self:isControlDown("left") then
- self.facing = -1
- self:applyForce(-250, 0)
- -- Controlled speed limit
- if x < -self.MAX_VELOCITY then
- self:applyForce(250, 0)
- end
+ self:walkLeft()
end
if self:isControlDown("right") then
- self.facing = 1
- self:applyForce(250, 0)
- -- Controlled speed limit
- if x > self.MAX_VELOCITY then
- self:applyForce(-250, 0)
- end
+ self:walkRight()
end
end