fix: start simplification of the movement system

This commit is contained in:
Kazhnuz 2020-07-25 10:24:07 +02:00
parent 75914d694d
commit 8fe8f61821
2 changed files with 17 additions and 20 deletions

View file

@ -4,6 +4,10 @@ local Battler = Parent:extend()
function Battler:new(world, x, y, z) function Battler:new(world, x, y, z)
Battler.super.new(self, world, x, y, z) Battler.super.new(self, world, x, y, z)
self.start = {}
self.start.x = x
self.start.y = y
self.isBattler = true self.isBattler = true
self.speed = 3 self.speed = 3
self.isActive = false self.isActive = false

View file

@ -47,32 +47,21 @@ function Hero:initMovementSystem()
self:initJump() self:initJump()
end end
function Hero:getMovementDuration(dx, dy, factor) function Hero:goTo(dx, dy, duration, easing)
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, factor, easing)
local easing = easing or 'inOutQuad' 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 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, timerName) self.tweens:newTimer(duration + 0.02, "goTo")
end end
function Hero:jumpTo(dx, dy, size, timerName, spinjump, factor, easing) function Hero:jumpTo(dx, dy, sizeFactor, duration, spinjump, easing)
local easing = easing or 'inOutQuad' local easing = easing or 'inOutQuad'
local factor = factor or 1 local dist = utils.math.pointDistance(self.x, self.y, dx, dy)
local duration = math.max(self:getMovementDuration(dx, dy, factor), 0.30) local jumpHeight = dist * 8 * sizeFactor
self.tweens:newTween(0, duration, {x = dx, y = dy}, easing) self.tweens:newTween(0, duration, {x = dx, y = dy}, easing)
self.tweens:newTimer(duration + 0.02, timerName) self.tweens:newTimer(duration + 0.02, "jumpTo")
self:setJump(size, spinjump, duration) self:setJump(jumpHeight, spinjump, duration)
end end
function Hero:updateSpeed(dt) function Hero:updateSpeed(dt)
@ -164,12 +153,16 @@ function Hero:unblockChoregraphy()
self.currentlyBlocking = nil self.currentlyBlocking = nil
end end
function Hero:receiveSignal(signal) function Hero:timerResponse(signal)
if (self.currentlyBlocking ~= nil) then if ((self.currentlyBlocking ~= nil) and (signal == self.blockedBy)) then
self:unblockChoregraphy() self:unblockChoregraphy()
end end
end end
function Hero:choregraphyEnded()
self.direction = 1
end
-- ASSETS FUNCTIONS -- ASSETS FUNCTIONS
-- Load and play assets needed by the character -- Load and play assets needed by the character