improvement(cbs): improve character moving functions

This commit is contained in:
Kazhnuz 2019-08-24 21:06:05 +02:00
parent 651eaaaa90
commit 27876928ab

View file

@ -106,6 +106,8 @@ end
-- MOVE FUNCTIONS
-- All functions handling the moving
local MOVEMENT_DURATION = 0.20
function Hero:initMovementSystem()
self.startx, self.starty = self.x, self.y
self.xprevious, self.yprevious = self.x, self.y
@ -115,16 +117,24 @@ function Hero:initMovementSystem()
self:initJump()
end
function Hero:getMovementDuration(dx, dy, duration)
local duration = duration or MOVEMENT_DURATION
local coef = 0.8
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 = duration or 0.66
self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'linear')
self.tweens:newTimer(DURATION + 0.02, timerName)
local duration = self:getMovementDuration(dx, dy, duration)
self.tweens:newTween(0, duration, {x = dx, y = dy}, 'inOutQuad')
self.tweens:newTimer(duration + 0.02, timerName)
end
function Hero:jumpTo(dx, dy, size, timerName, spinjump, duration)
local DURATION = duration or 0.66
self:goTo(dx, dy, timerName, DURATION)
self:setJump(size, spinjump, DURATION)
local duration = self:getMovementDuration(dx, dy, duration)
self:goTo(dx, dy, timerName, duration)
self:setJump(size, spinjump, duration)
end
function Hero:updateSpeed(dt)