diff options
author | Aki <nthirtyone@gmail.com> | 2017-09-29 13:17:54 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2017-09-29 13:17:54 +0200 |
commit | 6d61fb66d72bb668d71479d3ed5f40b51041639e (patch) | |
tree | 93091a80f6ec117bd2185544fd425473eecc5b1e /not/Hero.lua | |
parent | 356054d6dc0fffc280e893ec4385559b4c618de2 (diff) | |
download | roflnauts-6d61fb66d72bb668d71479d3ed5f40b51041639e.zip roflnauts-6d61fb66d72bb668d71479d3ed5f40b51041639e.tar.gz roflnauts-6d61fb66d72bb668d71479d3ed5f40b51041639e.tar.bz2 |
Moved update part of jumping from Player to Hero
isJumping is now a method
added debugging information on player jumps
Diffstat (limited to 'not/Hero.lua')
-rw-r--r-- | not/Hero.lua | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/not/Hero.lua b/not/Hero.lua index 2e1f1f0..b3edfbf 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.isJumping = false self.spawntimer = 2 self.punchCooldown = 0 -- TODO: Pass loaded portrait from menu to Hero. @@ -140,6 +139,13 @@ function Hero:update (dt) self:setLinearVelocity(38*self.facing, 0) end end + + -- Jumping. + if self:isJumping() and self.jumpTimer > 0 and (self.jumpCounter == 0 or self.jumpCounter == 1) then + local x = self:getLinearVelocity() + self:setLinearVelocity(x,-160) + self.jumpTimer = self.jumpTimer - dt + end end --- Damps linear velocity every frame by applying minor force to body. @@ -175,6 +181,13 @@ end function Hero:draw (debug) if not self.isAlive then return end Hero.__super.draw(self, debug) + if debug then + local x, y = self:getPosition() + love.graphics.setColor(255, 50, 50) + love.graphics.setFont(Font) + local msg = string.format("%d %s %s", self.jumpCounter, tostring(self.jumpTimer > 0), tostring(self:isJumping())) + love.graphics.print(msg, x + 10, y) + end end -- TODO: Hero@drawTag's printf is not readable. @@ -233,6 +246,10 @@ function Hero:land () self:createEffect("land") end +function Hero:isJumping () + return false +end + function Hero:isWalking () return self:isWalkingLeft() or self:isWalkingRight() end |