From 8dd4e7ba62656eba970f9d85711d9581657ce6fb Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 6 Aug 2021 23:47:20 +0200 Subject: [PATCH] improvement: use a 360 motion system --- .../scenes/battlesystem/actors/movable.lua | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua index dc1ab7e..e5cf41b 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua @@ -28,6 +28,8 @@ end function Movable:initMovementSystem() self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z self.xspeed, self.yspeed, self.zspeed = 0,0,0 + self.speed = 0 + self.angle = 0 self.direction = self.start.direction self.directionPrevious = self.start.direction self.directionLocked = false @@ -43,6 +45,7 @@ end function Movable:stopMoving() self.xspeed, self.yspeed, self.zspeed = 0,0,0 + self.speed = 0 if (self.movementType == MOVEMENT_TWEENER) then self:unlockTag("goTo") self.tweens:removeNamedTween("goTo") @@ -108,13 +111,18 @@ end -- MOTION HANDLING -function Movable:setMotion(xspeed, yspeed) - self.xspeed = xspeed - self.yspeed = yspeed +function Movable:setMotion(speed, angle) + self.speed = speed + self.angle = angle self.movementType = MOVEMENT_MOTION end +function Movable:setMotionToPoint(speed, dx, dy) + self:setMotion(speed, utils.math.pointDirection(self.x, self.y, dx, dy)) +end + function Movable:updateMotion(dt) + self.xspeed, self.yspeed = utils.math.lengthdir(self.speed, self.angle) self.x = self.x + (self.xspeed) * dt self.y = self.y + (self.yspeed) * dt end @@ -160,11 +168,9 @@ end function Movable:jumpTo(dx, dy, height, speed, useDefaultAnimation) height = height or 4 - speed = speed or 8 + self:setMotionToPoint(speed, dx, dy) + self:setJump(height, 0, useDefaultAnimation) - local dir = utils.math.pointDirection(self.x, self.y, dx, dy) - local hspeed, vspeed = utils.math.lengthdir(speed, dir) - self:setMotion(hspeed, vspeed) self.jump.isMotionJump = true end