diff --git a/sonic-radiance.love/game/utils/choregraphy/arguments.lua b/sonic-radiance.love/game/utils/choregraphy/arguments.lua index c0eb5ed..e4ce5a5 100644 --- a/sonic-radiance.love/game/utils/choregraphy/arguments.lua +++ b/sonic-radiance.love/game/utils/choregraphy/arguments.lua @@ -5,7 +5,7 @@ return { ["sendDamage"] = {"power", "accuracy", "isSpecial", "isAerial"}, ["goTo"] = {"origin", "x", "y", "duration", "blockProcess"}, ["setAnimation"] = {"animation", "blockProcess"}, - ["jump"] = {"power", "blockProcess"}, + ["jump"] = {"power", "bounceNumber", "blockProcess"}, ["jumpTo"] = {"origin", "x", "y", "duration", "blockProcess"}, ["jumpBack"] = {"duration", "blockProcess"}, --[name] = {args}, diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 84e0602..944637f 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -1,6 +1,12 @@ local Battler = require("scenes.battlesystem.actors.battler") local Hero = Battler:extend() +local MOVEMENT_NONE = "none" +local MOVEMENT_TWEENER = "tweener" +local MOVEMENT_MOTION = "motion" + +local ZGRAVITY = 0.2 + -- INIT FUNCTIONS -- Initialize the hero @@ -21,12 +27,9 @@ end function Hero:update(dt) Hero.super.update(self, dt) - -- Calculate speed to calculate animation speed - self:updateSpeed(dt) + self:updateMovement(dt) - self.xprevious = self.x - self.yprevious = self.y - self.zprevious = self.z + self:updateAnimation(dt) end -- MOVE FUNCTIONS @@ -35,22 +38,47 @@ end local MOVEMENT_DURATION = 0.20 function Hero:initMovementSystem() - self.startx, self.starty = self.x, self.y self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z + self.xspeed, self.yspeed, self.zspeed = 0,0,0 self.direction = 1 self.directionPrevious = 1 self.directionLocked = false - self.unlockDirection = true + + self.movementType = MOVEMENT_NONE self:initJump() end +function Hero:updateMovement(dt) + if (self.movementType == MOVEMENT_TWEENER) then + self:updateTweenerSpeed(dt) + elseif (self.movementType == MOVEMENT_MOTION) then + self:updateMotion(dt) + end + self.gspeed = math.sqrt(self.xspeed^2 + self.yspeed^2) + + self:updateDirection(dt) + self:updateJump(dt) + self:updatePreviousPosition(dt) +end + +function Hero:updatePreviousPosition() + self.xprevious = self.x + self.yprevious = self.y + self.zprevious = self.z +end + +-- Tweener movement functions + function Hero:goTo(dx, dy, duration, easing) local easing = easing or 'inOutQuad' if duration > 0 then self.tweens:newTween(0, duration, {x = dx, y = dy}, easing) end self.tweens:newTimer(duration + 0.02, "goTo") + self.tweens:newTimer(duration + 0.02, "resetMovement") + + self.movementType = MOVEMENT_TWEENER end function Hero:jumpTo(dx, dy, sizeFactor, duration, spinjump, easing) @@ -62,75 +90,81 @@ function Hero:jumpTo(dx, dy, sizeFactor, duration, spinjump, easing) self:setJump(jumpHeight, spinjump, duration) end -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 +function Hero:updateTweenerSpeed(dt) + self.xspeed = (self.x - self.xprevious) / dt + self.yspeed = (self.y - self.yprevious) / dt +end - self.gspeed = math.sqrt(self.xspeed^2 + self.yspeed^2) +-- MOTION HANDLING +function Hero:setMotion(xspeed, yspeed) + self.xspeed = xspeed + self.yspeed = yspeed + self.movementType = MOVEMENT_MOTION +end + +function Hero:updateMotion(dt) + self.x = self.x + (self.xspeed) * dt + self.y = self.y + (self.yspeed) * dt +end + +function Hero:endMotion() + self.movementType = MOVEMENT_NONE + self.xspeed = 0 + self.yspeed = 0 +end + +-- Direction handling + +function Hero:updateDirection() -- Handle direction if math.abs(self.xspeed) > 0 then 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) end +-- Jump system + function Hero:initJump() self.jump = {} - self.jump.spin = false + self.jump.useDefaultAnimation = true + self.jump.isJumping = false + self.jump.bounceNumber = 0 + self.jump.isJumpingBack = false end -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') +function Hero:setJump(power, bounceNumber, useDefaultAnimation) + self.zspeed = power self.jump.spin = spinjump + self.jump.bounceNumber = bounceNumber + self.jump.isJumping = true end -function Hero:setMotionX(direction, speed) - self.motion = speed - self.motionDirection = direction +function Hero:jumpBack() + self:setJump(3, 0, true) + self:setMotion(-10, 0) + self.jump.isJumpingBack = true end -function Hero:applyMotion(dt) - if self.motion ~= 0 and self.motion ~= nil then - local dx = self.x + self.motion * self.motionDirection * dt - -- {1, 0, "line", 5, true} - local ox = self.choregraphy.startx + (self.choregraphy.effectArea[1] * self.choregraphy.direction) - local oy = self.choregraphy.starty + self.choregraphy.effectArea[2] - local shape = self.choregraphy.effectArea[3] - local size = self.choregraphy.effectArea[4] - local direction = self.choregraphy.direction - - local new_case_x = utils.math.round(dx) - local new_case_y = utils.math.round(self.y) - print(new_case_x, new_case_y, self.world:caseIsEmpty(new_case_x, new_case_y, self)) - if self.maputils.isInMask(dx, self.y, ox, oy, shape, size, direction) and self.world:caseIsEmpty(new_case_x, new_case_y, self) then - self.x = dx - else - self.x = dx - self.motion = 0 - if (self.blockingChoregraphy == 'action_dashForward') then - self:unblockChoregraphy() - self.direction = self.choregraphy.direction +function Hero:updateJump(dt) + if (self.jump.isJumping) then + self.zspeed = self.zspeed - ZGRAVITY + self.z = self.z + self.zspeed + if (self.z <= 0) then + if (self.jump.bounceNumber > 0) then + self.zspeed = self.zspeed * -0.5 + self.jump.bounceNumber = self.jump.bounceNumber - 1 + else + self.z = 0 + self.jump.isJumping = false + self.jump.spin = false + self:timerResponse("jump") + if (self.jump.isJumpingBack) then + self:endMotion() + end + self:changeAnimation("idle") end end end @@ -155,6 +189,10 @@ function Hero:timerResponse(signal) if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then self:unblockChoregraphy() end + + if (signal == "resetMovement") then + self.movementType = MOVEMENT_NONE + end end function Hero:choregraphyEnded() @@ -178,6 +216,18 @@ function Hero:animationEnded(animation) end end +function Hero:updateAnimation(dt) + if (self.z > 0 and self.jump.useDefaultAnimation) then + if self.zspeed > 0 then + self:changeAnimation("jump") + else + self:changeAnimation("fall") + end + end + + self:setCustomSpeed(self.gspeed * 320) +end + -- DRAW FUNCTIONS -- Draw everything related to the hero diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua index 2d6102b..3cc435d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua @@ -4,7 +4,6 @@ local baseURI = "scenes.battlesystem.controllers.fighters.systems.choregraphy.st actions["addGFX"] = require(baseURI .. "addGFX") actions["goTo"] = require(baseURI .. "goTo") -actions["jumpTo"] = require(baseURI .. "jumpTo") actions["jumpBack"] = require(baseURI .. "jumpBack") actions["playSFX"] = require(baseURI .. "playSFX") actions["sendDamage"] = require(baseURI .. "sendDamage") 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 0bf6000..bb33e2f 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,13 +7,12 @@ end function JumpBackStep:start() - local x, y = self.choregraphy.actor.start.x, self.choregraphy.actor.start.y - self.choregraphy.actor:jumpTo(x, y, 0.5, self.arguments.duration, false, "outQuad") + self.choregraphy.actor:jumpBack() if (self.arguments.blockProcess == false) then self:finish() else - self.choregraphy.actor:blockChoregraphy(self.arguments.blockProcess, self, "jumpTo") + self.choregraphy.actor:blockChoregraphy(self.arguments.blockProcess, self, "jump") end end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpTo.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpTo.lua deleted file mode 100644 index 978c2f1..0000000 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/jumpTo.lua +++ /dev/null @@ -1,28 +0,0 @@ -local StepParent = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step.parent" -local JumpToStep = StepParent:extend() - -function JumpToStep:new(controller, args) - JumpToStep.super.new(self, controller, args) -end - -function JumpToStep:start() - - local x, y = self:getStepCoordinate() - self.choregraphy.actor:jumpTo(x, y, 1, self.arguments.duration, true, "inOutQuad") - - if (self.arguments.blockProcess == false) then - self:finish() - else - self.choregraphy.actor:blockChoregraphy(self.arguments.blockProcess, self, "jumpTo") - end -end - -function JumpToStep:update(dt) - -end - -function JumpToStep:getSignal(signal) - -end - -return JumpToStep;