diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 2625c0e..76b5799 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -103,6 +103,7 @@ function Hero:update(dt) self.xprevious = self.x self.yprevious = self.y + self.zprevious = self.z end -- MOVE FUNCTIONS @@ -112,32 +113,39 @@ local MOVEMENT_DURATION = 0.20 function Hero:initMovementSystem() self.startx, self.starty = self.x, self.y - self.xprevious, self.yprevious = self.x, self.y + self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z self.direction = 1 self.directionPrevious = 1 + self.directionLocked = false + self.unlockDirection = true self:initJump() end -function Hero:getMovementDuration(dx, dy, duration) - local duration = duration or MOVEMENT_DURATION - local coef = 0.8 +function Hero:getMovementDuration(dx, dy, factor) + local factor = factor or 1 + local duration = MOVEMENT_DURATION / factor + local coef = 0.5 local dx, dy = dx, dy local distance = utils.math.pointDistance(self.x, self.y, dx, dy) * coef return duration * distance end -function Hero:goTo(dx, dy, timerName, duration) - local duration = math.max(self:getMovementDuration(dx, dy, duration), 0.30) +function Hero:goTo(dx, dy, timerName, factor, easing) + local easing = easing or 'inOutQuad' + local factor = factor or 1 + local duration = math.max(self:getMovementDuration(dx, dy, factor), 0.30) if duration > 0 then - self.tweens:newTween(0, duration, {x = dx, y = dy}, 'inOutQuad') + self.tweens:newTween(0, duration, {x = dx, y = dy}, easing) end self.tweens:newTimer(duration + 0.02, timerName) end -function Hero:jumpTo(dx, dy, size, timerName, spinjump, duration) - local duration = math.max(self:getMovementDuration(dx, dy, duration), 0.30) - self.tweens:newTween(0, duration, {x = dx, y = dy}, 'inOutQuad') +function Hero:jumpTo(dx, dy, size, timerName, spinjump, factor, easing) + local easing = easing or 'inOutQuad' + local factor = factor or 1 + local duration = math.max(self:getMovementDuration(dx, dy, factor), 0.30) + self.tweens:newTween(0, duration, {x = dx, y = dy}, easing) self.tweens:newTimer(duration + 0.02, timerName) self:setJump(size, spinjump, duration) end @@ -146,12 +154,28 @@ function Hero:updateSpeed(dt) self:applyMotion(dt) self.xspeed = self.x - self.xprevious self.yspeed = self.y - self.yprevious + self.zspeed = self.z - self.zprevious self.gspeed = math.sqrt(self.xspeed^2 + self.yspeed^2) -- Handle direction if math.abs(self.xspeed) > 0 then - self.direction = utils.math.sign(self.xspeed) + if (self.directionLocked == false) then + self.direction = utils.math.sign(self.xspeed) + end + else + if self.unlockDirection then + self.unlockDirection = false + self.directionLocked = false + end + end + + if self.z > 0 and self.jump.spin == false then + if self.zspeed > 0 then + self:changeAnimation("jump") + else + self:changeAnimation("fall") + end end self:setCustomSpeed(self.gspeed * 320) @@ -175,6 +199,7 @@ function Hero:setJump(size, spinjump, duration) local tweenDuration = duration / 2 self.tweens:newTween(0, tweenDuration, {z = size}, 'outQuad') self.tweens:newTween(tweenDuration, tweenDuration, {z = 0}, 'inQuad') + self.jump.spin = spinjump end function Hero:setMotionX(direction, speed) @@ -228,7 +253,7 @@ function Hero:receiveSignal(action_type, id) self:useSkill(id, self.world.cursor.x, self.world.cursor.y) elseif (action_type == "cursorMove") then self:changeAnimation("walk", true) - self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove') + self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove', 1) self.assets.sfx["woosh"]:play() self.world.cursor:unset( ) else @@ -238,7 +263,7 @@ end function Hero:receiveBackSignal() self.world.cursor:set(self.x, self.y, "cursorMove") - self:goTo(self.startx, self.starty, 'backMove') + self:goTo(self.startx, self.starty, 'backMove', 1) self.assets.sfx["woosh"]:play() self:changeAnimation("walk") @@ -256,6 +281,9 @@ function Hero:timerResponse(timer) elseif timer == 'backMove' then self:changeAnimation("idle") self.direction = self.directionPrevious + elseif timer == 'action_jumpBack' then + self.unlockDirection = true + self.choregraphy.changeAction = true elseif timer == self.choregraphy.blockedBy and self.choregraphy.changeAction == false then self.choregraphy.changeAction = true end @@ -412,13 +440,23 @@ end function Hero:chorJump(args) local xx, yy + local spinjump = true + local factor = 1 + local easing = 'inOutQuad' if args.name == "jumpBack" then xx, yy = self.choregraphy.startx, self.choregraphy.starty + self.directionLocked = true + spinjump = false + factor = 2 + easing = 'outQuad' elseif args.name == "jumpToCursor" then xx, yy = self.choregraphy.dx, self.choregraphy.dy end - self:jumpTo(xx, yy, 48, "action_jumpBack", false) + local dist = utils.math.pointDistance(self.x, self.y, xx, yy) + local jumpHeight = dist * 16 / factor + + self:jumpTo(xx, yy, jumpHeight, "action_jumpBack", spinjump, 1, easing) self:blockChoregraphy(args.blockProcess, "action_jumpBack") end