improvement: revamp the whole motion system
This commit is contained in:
parent
7364e5c206
commit
cce03643f6
5 changed files with 110 additions and 90 deletions
|
@ -5,7 +5,7 @@ return {
|
||||||
["sendDamage"] = {"power", "accuracy", "isSpecial", "isAerial"},
|
["sendDamage"] = {"power", "accuracy", "isSpecial", "isAerial"},
|
||||||
["goTo"] = {"origin", "x", "y", "duration", "blockProcess"},
|
["goTo"] = {"origin", "x", "y", "duration", "blockProcess"},
|
||||||
["setAnimation"] = {"animation", "blockProcess"},
|
["setAnimation"] = {"animation", "blockProcess"},
|
||||||
["jump"] = {"power", "blockProcess"},
|
["jump"] = {"power", "bounceNumber", "blockProcess"},
|
||||||
["jumpTo"] = {"origin", "x", "y", "duration", "blockProcess"},
|
["jumpTo"] = {"origin", "x", "y", "duration", "blockProcess"},
|
||||||
["jumpBack"] = {"duration", "blockProcess"},
|
["jumpBack"] = {"duration", "blockProcess"},
|
||||||
--[name] = {args},
|
--[name] = {args},
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
local Battler = require("scenes.battlesystem.actors.battler")
|
local Battler = require("scenes.battlesystem.actors.battler")
|
||||||
local Hero = Battler:extend()
|
local Hero = Battler:extend()
|
||||||
|
|
||||||
|
local MOVEMENT_NONE = "none"
|
||||||
|
local MOVEMENT_TWEENER = "tweener"
|
||||||
|
local MOVEMENT_MOTION = "motion"
|
||||||
|
|
||||||
|
local ZGRAVITY = 0.2
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialize the hero
|
-- Initialize the hero
|
||||||
|
|
||||||
|
@ -21,12 +27,9 @@ end
|
||||||
|
|
||||||
function Hero:update(dt)
|
function Hero:update(dt)
|
||||||
Hero.super.update(self, dt)
|
Hero.super.update(self, dt)
|
||||||
-- Calculate speed to calculate animation speed
|
self:updateMovement(dt)
|
||||||
self:updateSpeed(dt)
|
|
||||||
|
|
||||||
self.xprevious = self.x
|
self:updateAnimation(dt)
|
||||||
self.yprevious = self.y
|
|
||||||
self.zprevious = self.z
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MOVE FUNCTIONS
|
-- MOVE FUNCTIONS
|
||||||
|
@ -35,22 +38,47 @@ end
|
||||||
local MOVEMENT_DURATION = 0.20
|
local MOVEMENT_DURATION = 0.20
|
||||||
|
|
||||||
function Hero:initMovementSystem()
|
function Hero:initMovementSystem()
|
||||||
self.startx, self.starty = self.x, self.y
|
|
||||||
self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z
|
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.direction = 1
|
||||||
self.directionPrevious = 1
|
self.directionPrevious = 1
|
||||||
self.directionLocked = false
|
self.directionLocked = false
|
||||||
self.unlockDirection = true
|
|
||||||
|
self.movementType = MOVEMENT_NONE
|
||||||
|
|
||||||
self:initJump()
|
self:initJump()
|
||||||
end
|
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)
|
function Hero:goTo(dx, dy, duration, easing)
|
||||||
local easing = easing or 'inOutQuad'
|
local easing = easing or 'inOutQuad'
|
||||||
if duration > 0 then
|
if duration > 0 then
|
||||||
self.tweens:newTween(0, duration, {x = dx, y = dy}, easing)
|
self.tweens:newTween(0, duration, {x = dx, y = dy}, easing)
|
||||||
end
|
end
|
||||||
self.tweens:newTimer(duration + 0.02, "goTo")
|
self.tweens:newTimer(duration + 0.02, "goTo")
|
||||||
|
self.tweens:newTimer(duration + 0.02, "resetMovement")
|
||||||
|
|
||||||
|
self.movementType = MOVEMENT_TWEENER
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:jumpTo(dx, dy, sizeFactor, duration, spinjump, easing)
|
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)
|
self:setJump(jumpHeight, spinjump, duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:updateSpeed(dt)
|
function Hero:updateTweenerSpeed(dt)
|
||||||
self:applyMotion(dt)
|
self.xspeed = (self.x - self.xprevious) / dt
|
||||||
self.xspeed = self.x - self.xprevious
|
self.yspeed = (self.y - self.yprevious) / dt
|
||||||
self.yspeed = self.y - self.yprevious
|
end
|
||||||
self.zspeed = self.z - self.zprevious
|
|
||||||
|
|
||||||
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
|
-- Handle direction
|
||||||
if math.abs(self.xspeed) > 0 then
|
if math.abs(self.xspeed) > 0 then
|
||||||
if (self.directionLocked == false) then
|
if (self.directionLocked == false) then
|
||||||
self.direction = utils.math.sign(self.xspeed)
|
self.direction = utils.math.sign(self.xspeed)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
if self.unlockDirection then
|
|
||||||
self.unlockDirection = false
|
|
||||||
self.directionLocked = false
|
|
||||||
end
|
|
||||||
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
|
end
|
||||||
|
|
||||||
|
-- Jump system
|
||||||
|
|
||||||
function Hero:initJump()
|
function Hero:initJump()
|
||||||
self.jump = {}
|
self.jump = {}
|
||||||
self.jump.spin = false
|
self.jump.useDefaultAnimation = true
|
||||||
|
self.jump.isJumping = false
|
||||||
|
self.jump.bounceNumber = 0
|
||||||
|
self.jump.isJumpingBack = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:setJump(size, spinjump, duration)
|
function Hero:setJump(power, bounceNumber, useDefaultAnimation)
|
||||||
local tweenDuration = duration / 2
|
self.zspeed = power
|
||||||
self.tweens:newTween(0, tweenDuration, {z = size}, 'outQuad')
|
|
||||||
self.tweens:newTween(tweenDuration, tweenDuration, {z = 0}, 'inQuad')
|
|
||||||
self.jump.spin = spinjump
|
self.jump.spin = spinjump
|
||||||
|
self.jump.bounceNumber = bounceNumber
|
||||||
|
self.jump.isJumping = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:setMotionX(direction, speed)
|
function Hero:jumpBack()
|
||||||
self.motion = speed
|
self:setJump(3, 0, true)
|
||||||
self.motionDirection = direction
|
self:setMotion(-10, 0)
|
||||||
|
self.jump.isJumpingBack = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:applyMotion(dt)
|
function Hero:updateJump(dt)
|
||||||
if self.motion ~= 0 and self.motion ~= nil then
|
if (self.jump.isJumping) then
|
||||||
local dx = self.x + self.motion * self.motionDirection * dt
|
self.zspeed = self.zspeed - ZGRAVITY
|
||||||
-- {1, 0, "line", 5, true}
|
self.z = self.z + self.zspeed
|
||||||
local ox = self.choregraphy.startx + (self.choregraphy.effectArea[1] * self.choregraphy.direction)
|
if (self.z <= 0) then
|
||||||
local oy = self.choregraphy.starty + self.choregraphy.effectArea[2]
|
if (self.jump.bounceNumber > 0) then
|
||||||
local shape = self.choregraphy.effectArea[3]
|
self.zspeed = self.zspeed * -0.5
|
||||||
local size = self.choregraphy.effectArea[4]
|
self.jump.bounceNumber = self.jump.bounceNumber - 1
|
||||||
local direction = self.choregraphy.direction
|
else
|
||||||
|
self.z = 0
|
||||||
local new_case_x = utils.math.round(dx)
|
self.jump.isJumping = false
|
||||||
local new_case_y = utils.math.round(self.y)
|
self.jump.spin = false
|
||||||
print(new_case_x, new_case_y, self.world:caseIsEmpty(new_case_x, new_case_y, self))
|
self:timerResponse("jump")
|
||||||
if self.maputils.isInMask(dx, self.y, ox, oy, shape, size, direction) and self.world:caseIsEmpty(new_case_x, new_case_y, self) then
|
if (self.jump.isJumpingBack) then
|
||||||
self.x = dx
|
self:endMotion()
|
||||||
else
|
end
|
||||||
self.x = dx
|
self:changeAnimation("idle")
|
||||||
self.motion = 0
|
|
||||||
if (self.blockingChoregraphy == 'action_dashForward') then
|
|
||||||
self:unblockChoregraphy()
|
|
||||||
self.direction = self.choregraphy.direction
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -155,6 +189,10 @@ function Hero:timerResponse(signal)
|
||||||
if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
|
if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
|
||||||
self:unblockChoregraphy()
|
self:unblockChoregraphy()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (signal == "resetMovement") then
|
||||||
|
self.movementType = MOVEMENT_NONE
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:choregraphyEnded()
|
function Hero:choregraphyEnded()
|
||||||
|
@ -178,6 +216,18 @@ function Hero:animationEnded(animation)
|
||||||
end
|
end
|
||||||
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 FUNCTIONS
|
||||||
-- Draw everything related to the hero
|
-- Draw everything related to the hero
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ local baseURI = "scenes.battlesystem.controllers.fighters.systems.choregraphy.st
|
||||||
|
|
||||||
actions["addGFX"] = require(baseURI .. "addGFX")
|
actions["addGFX"] = require(baseURI .. "addGFX")
|
||||||
actions["goTo"] = require(baseURI .. "goTo")
|
actions["goTo"] = require(baseURI .. "goTo")
|
||||||
actions["jumpTo"] = require(baseURI .. "jumpTo")
|
|
||||||
actions["jumpBack"] = require(baseURI .. "jumpBack")
|
actions["jumpBack"] = require(baseURI .. "jumpBack")
|
||||||
actions["playSFX"] = require(baseURI .. "playSFX")
|
actions["playSFX"] = require(baseURI .. "playSFX")
|
||||||
actions["sendDamage"] = require(baseURI .. "sendDamage")
|
actions["sendDamage"] = require(baseURI .. "sendDamage")
|
||||||
|
|
|
@ -7,13 +7,12 @@ end
|
||||||
|
|
||||||
function JumpBackStep:start()
|
function JumpBackStep:start()
|
||||||
|
|
||||||
local x, y = self.choregraphy.actor.start.x, self.choregraphy.actor.start.y
|
self.choregraphy.actor:jumpBack()
|
||||||
self.choregraphy.actor:jumpTo(x, y, 0.5, self.arguments.duration, false, "outQuad")
|
|
||||||
|
|
||||||
if (self.arguments.blockProcess == false) then
|
if (self.arguments.blockProcess == false) then
|
||||||
self:finish()
|
self:finish()
|
||||||
else
|
else
|
||||||
self.choregraphy.actor:blockChoregraphy(self.arguments.blockProcess, self, "jumpTo")
|
self.choregraphy.actor:blockChoregraphy(self.arguments.blockProcess, self, "jump")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
Loading…
Reference in a new issue