diff options
author | Aki <nthirtyone@gmail.com> | 2017-09-23 14:08:32 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-09-23 14:08:32 +0200 |
commit | 19a19538c205fce74550c20d648fb239e26f0cf3 (patch) | |
tree | 59339bebc67f2eb9ab0f7620a1163d469667155d /not/Hero.lua | |
parent | d651584d7a550a507670d9e028ed1c9be5fae427 (diff) | |
download | roflnauts-19a19538c205fce74550c20d648fb239e26f0cf3.zip roflnauts-19a19538c205fce74550c20d648fb239e26f0cf3.tar.gz roflnauts-19a19538c205fce74550c20d648fb239e26f0cf3.tar.bz2 |
Hero walking moved from Player, separated into methods
Diffstat (limited to 'not/Hero.lua')
-rw-r--r-- | not/Hero.lua | 20 |
1 files changed, 20 insertions, 0 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`. |