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 self.movementType = MOVEMENT_TWEENER
end 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) function Battler:updateTweenerSpeed(dt)
self.xspeed = (self.x - self.xprevious) / dt self.xspeed = (self.x - self.xprevious) / dt
self.yspeed = (self.y - self.yprevious) / dt self.yspeed = (self.y - self.yprevious) / dt
@ -203,7 +194,7 @@ function Battler:initJump()
self.jump.useDefaultAnimation = true self.jump.useDefaultAnimation = true
self.jump.isJumping = false self.jump.isJumping = false
self.jump.bounceNumber = 0 self.jump.bounceNumber = 0
self.jump.isJumpingBack = false self.jump.isMotionJump = false
end end
function Battler:setJump(power, bounceNumber, useDefaultAnimation) function Battler:setJump(power, bounceNumber, useDefaultAnimation)
@ -213,12 +204,18 @@ function Battler:setJump(power, bounceNumber, useDefaultAnimation)
self.jump.isJumping = true self.jump.isJumping = true
end end
function Battler:jumpBack() function Battler:jumpTo(dx, dy, height, speed, spinjump)
self:setJump(4, 0, true) height = height or 4
local dir = utils.math.pointDirection(self.x, self.y, self.start.x, self.start.y) speed = speed or 8
local hspeed, vspeed = utils.math.lengthdir(8, dir) 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: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 end
function Battler:updateJump(dt) function Battler:updateJump(dt)
@ -234,7 +231,7 @@ function Battler:updateJump(dt)
self.jump.isJumping = false self.jump.isJumping = false
self.jump.spin = false self.jump.spin = false
self:timerResponse("jump") self:timerResponse("jump")
if (self.jump.isJumpingBack) then if (self.jump.isMotionJump) then
self:endMotion() self:endMotion()
end end
self:changeAnimation("idle") self:changeAnimation("idle")

View file

@ -7,7 +7,7 @@ end
function JumpBackStep:start() 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") self.choregraphy.actor:addTaggedAction(self.tag, self.choregraphy, "jump")
if (self.arguments.blockProcess == false) then if (self.arguments.blockProcess == false) then