summaryrefslogtreecommitdiffhomepage
path: root/not
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2018-04-09 20:27:54 +0200
committerAki <nthirtyone@gmail.com>2018-04-09 20:27:54 +0200
commit21880f5d084f04f0403301bac53dc9587eea198d (patch)
tree0de1b35c12a3902cba8ddd6861378b298635917d /not
parent6bad1609ca28ce88dbe75207e524ce8d67ec2a61 (diff)
downloadroflnauts-21880f5d084f04f0403301bac53dc9587eea198d.zip
roflnauts-21880f5d084f04f0403301bac53dc9587eea198d.tar.gz
roflnauts-21880f5d084f04f0403301bac53dc9587eea198d.tar.bz2
Restructured Hero a little bit more
Diffstat (limited to 'not')
-rw-r--r--not/Hero.lua85
1 files changed, 43 insertions, 42 deletions
diff --git a/not/Hero.lua b/not/Hero.lua
index 38eb749..7c818ee 100644
--- a/not/Hero.lua
+++ b/not/Hero.lua
@@ -176,6 +176,37 @@ function Hero:update (dt)
end
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
+
+--- Damps linear velocity every frame by applying minor force to body.
+function Hero:dampVelocity (dt)
+ if not self:isWalking() then
+ local face
+ local x, y = self:getLinearVelocity()
+ if x < -12 then
+ face = 1
+ elseif x > 12 then
+ face = -1
+ else
+ face = 0
+ end
+ self:applyForce(40*face,0)
+ if not self.inAir then
+ self:applyForce(80*face,0)
+ end
+ end
+end
+
--- Called each time Hero starts walking.
-- Is not called when direction of walking is changed.
function Hero:onWalkingStarted ()
@@ -223,36 +254,6 @@ function Hero:onJumpStopped ()
self.jumpTimer = Hero.JUMP_TIMER
end
---- Damps linear velocity every frame by applying minor force to body.
-function Hero:dampVelocity (dt)
- if not self:isWalking() then
- local face
- local x, y = self:getLinearVelocity()
- if x < -12 then
- face = 1
- elseif x > 12 then
- face = -1
- else
- face = 0
- end
- self:applyForce(40*face,0)
- if not self.inAir then
- self:applyForce(80*face,0)
- end
- end
-end
-
--- TODO: comment them and place them somewhere properly
-function Hero:getAngle ()
- return self.angle
-end
-function Hero:getHorizontalMirror ()
- return self.facing
-end
-function Hero:getOffset ()
- return 12,15
-end
-
function Hero:draw (debug)
if not self.isAlive then return end
Hero.__super.draw(self, debug)
@@ -321,6 +322,18 @@ function Hero:land ()
self:createEffect("land")
end
+function Hero:getAngle ()
+ return self.angle
+end
+
+function Hero:getHorizontalMirror ()
+ return self.facing
+end
+
+function Hero:getOffset ()
+ return 12,15
+end
+
function Hero:isJumping ()
return false
end
@@ -337,18 +350,6 @@ function Hero:isWalkingRight ()
return false
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
-
-- 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`.