improvement(cbs): improve character moving functions
This commit is contained in:
parent
651eaaaa90
commit
27876928ab
1 changed files with 16 additions and 6 deletions
|
@ -106,6 +106,8 @@ end
|
||||||
-- MOVE FUNCTIONS
|
-- MOVE FUNCTIONS
|
||||||
-- All functions handling the moving
|
-- All functions handling the moving
|
||||||
|
|
||||||
|
local MOVEMENT_DURATION = 0.20
|
||||||
|
|
||||||
function Hero:initMovementSystem()
|
function Hero:initMovementSystem()
|
||||||
self.startx, self.starty = self.x, self.y
|
self.startx, self.starty = self.x, self.y
|
||||||
self.xprevious, self.yprevious = self.x, self.y
|
self.xprevious, self.yprevious = self.x, self.y
|
||||||
|
@ -115,16 +117,24 @@ function Hero:initMovementSystem()
|
||||||
self:initJump()
|
self:initJump()
|
||||||
end
|
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)
|
function Hero:goTo(dx, dy, timerName, duration)
|
||||||
local DURATION = duration or 0.66
|
local duration = self:getMovementDuration(dx, dy, duration)
|
||||||
self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'linear')
|
self.tweens:newTween(0, duration, {x = dx, y = dy}, 'inOutQuad')
|
||||||
self.tweens:newTimer(DURATION + 0.02, timerName)
|
self.tweens:newTimer(duration + 0.02, timerName)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:jumpTo(dx, dy, size, timerName, spinjump, duration)
|
function Hero:jumpTo(dx, dy, size, timerName, spinjump, duration)
|
||||||
local DURATION = duration or 0.66
|
local duration = self:getMovementDuration(dx, dy, duration)
|
||||||
self:goTo(dx, dy, timerName, DURATION)
|
self:goTo(dx, dy, timerName, duration)
|
||||||
self:setJump(size, spinjump, DURATION)
|
self:setJump(size, spinjump, duration)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:updateSpeed(dt)
|
function Hero:updateSpeed(dt)
|
||||||
|
|
Loading…
Reference in a new issue