improvement: refactor jumping

This commit is contained in:
Kazhnuz 2021-07-18 08:47:37 +02:00
parent ed099bd77f
commit 5b0dde30e0
2 changed files with 14 additions and 17 deletions

View file

@ -152,15 +152,6 @@ function Battler:goTo(dx, dy, duration, easing)
self.movementType = MOVEMENT_TWEENER
end
function Battler:jumpTo(dx, dy, sizeFactor, duration, spinjump, easing)
local easing = easing or 'inOutQuad'
local dist = utils.math.pointDistance(self.x, self.y, dx, dy)
local jumpHeight = dist * 8 * sizeFactor
self.tweens:newTween(0, duration, {x = dx, y = dy}, easing)
self.tweens:newTimer(duration + 0.02, "jumpTo")
self:setJump(jumpHeight, spinjump, duration)
end
function Battler:updateTweenerSpeed(dt)
self.xspeed = (self.x - self.xprevious) / dt
self.yspeed = (self.y - self.yprevious) / dt
@ -203,7 +194,7 @@ function Battler:initJump()
self.jump.useDefaultAnimation = true
self.jump.isJumping = false
self.jump.bounceNumber = 0
self.jump.isJumpingBack = false
self.jump.isMotionJump = false
end
function Battler:setJump(power, bounceNumber, useDefaultAnimation)
@ -213,12 +204,18 @@ function Battler:setJump(power, bounceNumber, useDefaultAnimation)
self.jump.isJumping = true
end
function Battler:jumpBack()
self:setJump(4, 0, true)
local dir = utils.math.pointDirection(self.x, self.y, self.start.x, self.start.y)
local hspeed, vspeed = utils.math.lengthdir(8, dir)
function Battler:jumpTo(dx, dy, height, speed, spinjump)
height = height or 4
speed = speed or 8
self:setJump(height, 0, spinjump)
local dir = utils.math.pointDirection(self.x, self.y, dx, dy)
local hspeed, vspeed = utils.math.lengthdir(speed, dir)
self:setMotion(hspeed, vspeed)
self.jump.isJumpingBack = true
self.jump.isMotionJump = true
end
function Battler:jumpBack(height, speed)
self:jumpTo(self.start.x, self.start.y, height, speed, false)
end
function Battler:updateJump(dt)
@ -234,7 +231,7 @@ function Battler:updateJump(dt)
self.jump.isJumping = false
self.jump.spin = false
self:timerResponse("jump")
if (self.jump.isJumpingBack) then
if (self.jump.isMotionJump) then
self:endMotion()
end
self:changeAnimation("idle")

View file

@ -7,7 +7,7 @@ end
function JumpBackStep:start()
self.choregraphy.actor:jumpBack()
self.choregraphy.actor:jumpBack(self.arguments.height, self.arguments.speed)
self.choregraphy.actor:addTaggedAction(self.tag, self.choregraphy, "jump")
if (self.arguments.blockProcess == false) then