From 5b0dde30e0a795738de4e1d16f487c5b9b5bd3e2 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 18 Jul 2021 08:47:37 +0200 Subject: [PATCH] improvement: refactor jumping --- .../scenes/battlesystem/actors/battler.lua | 29 +++++++++---------- .../systems/choregraphy/step/jumpBack.lua | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua index 56638c4..5d1ff26 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua @@ -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") diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpBack.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpBack.lua index 9aeb743..78e8060 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpBack.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpBack.lua @@ -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