From ee1995b91b063f725947153712ba0888fd1cf3a0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Aug 2021 10:26:29 +0200 Subject: [PATCH] improvement: add vertical motion to motion --- .../scenes/battlesystem/actors/movable.lua | 69 ++++++++++++------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua index 65812ef..48a1cd7 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua @@ -6,7 +6,7 @@ local MOVEMENT_TWEENER = "tweener" local MOVEMENT_MOTION = "motion" local MOVEMENT_TARGET = "target" -local ZGRAVITY = 0.2 +local ZGRAVITY = 12 local MIDDLE_ARENA = 6 @@ -31,11 +31,13 @@ function Movable:initMovementSystem() self.xspeed, self.yspeed, self.zspeed = 0,0,0 self.speed = 0 self.angle = 0 + self.vertAngle = 0 self.direction = self.start.direction self.directionPrevious = self.start.direction self.directionLocked = false self.movementType = MOVEMENT_NONE + self.motion3D = false self:initJump() self:resetTarget() @@ -68,7 +70,6 @@ function Movable:updateMovement(dt) end self:updateDirection() - self:updateJump(dt) self:updatePreviousPosition() end @@ -122,9 +123,25 @@ end function Movable:updateMotion(dt) self:checkTarget(dt) - self.xspeed, self.yspeed = utils.math.lengthdir(self.speed, self.angle) + self.xspeed, self.yspeed, self.zspeed = self:getMotionCoord() self.x = self.x + (self.xspeed) * dt self.y = self.y + (self.yspeed) * dt + self.z = self.z + (self.zspeed) * dt + + self:checkGround() +end + +function Movable:getMotionCoord() + local gspeed, xspeed, yspeed, zspeed + if (self.motion3D) then + gspeed, zspeed = utils.math.lengthdir(self.speed, self.vertAngle) + xspeed, yspeed = utils.math.lengthdir(gspeed, self.angle) + else + xspeed, yspeed = utils.math.lengthdir(self.speed, self.angle) + zspeed = self:getJumpMotion() + end + + return xspeed, yspeed, zspeed end function Movable:endMotion() @@ -211,7 +228,7 @@ function Movable:stopJumping() end function Movable:setJump(power, bounceNumber, useDefaultAnimation) - self.zspeed = power + self.zspeed = (power * 60) self.jump.useDefaultAnimation = useDefaultAnimation self.jump.bounceNumber = bounceNumber self.jump.isJumping = true @@ -229,25 +246,31 @@ function Movable:jumpBack(height, speed) self:jumpTo(self.start.x, self.start.y, height, speed, true) end -function Movable:updateJump(dt) - if (self.jump.isJumping) then - self.zspeed = self.zspeed - ZGRAVITY - self.z = self.z + self.zspeed - if (self.z <= 0) then - if (self.jump.bounceNumber > 0) then - self.zspeed = self.zspeed * -0.5 - self.jump.bounceNumber = self.jump.bounceNumber - 1 - else - self.z = 0 - self.jump.isJumping = false - self.jump.spin = false - self:timerResponse("jump") - if (self.jump.isMotionJump) then - self:endMotion() - end - self:changeAnimation("idle") - end +function Movable:getJumpMotion() + if (self.jump.isJumping) then + return self.zspeed - ZGRAVITY + else + return 0 end - end end + +function Movable:checkGround() + if (self.z <= 0 and self.jump.isJumping) then + if (self.jump.bounceNumber > 0) then + self.zspeed = self.zspeed * -0.5 + self.jump.bounceNumber = self.jump.bounceNumber - 1 + else + self.z = 0 + self.zspeed = 0 + self.jump.isJumping = false + self.jump.spin = false + self:finishAction("jump") + if (self.jump.isMotionJump) then + self:endMotion() + end + self:changeAnimation("idle") + end + end +end + return Movable \ No newline at end of file