improvement: add vertical motion to motion
This commit is contained in:
parent
0c4e960ec9
commit
ee1995b91b
1 changed files with 46 additions and 23 deletions
|
@ -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,19 +246,25 @@ function Movable:jumpBack(height, speed)
|
|||
self:jumpTo(self.start.x, self.start.y, height, speed, true)
|
||||
end
|
||||
|
||||
function Movable:updateJump(dt)
|
||||
function Movable:getJumpMotion()
|
||||
if (self.jump.isJumping) then
|
||||
self.zspeed = self.zspeed - ZGRAVITY
|
||||
self.z = self.z + self.zspeed
|
||||
if (self.z <= 0) then
|
||||
return self.zspeed - ZGRAVITY
|
||||
else
|
||||
return 0
|
||||
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:timerResponse("jump")
|
||||
self:finishAction("jump")
|
||||
if (self.jump.isMotionJump) then
|
||||
self:endMotion()
|
||||
end
|
||||
|
@ -249,5 +272,5 @@ function Movable:updateJump(dt)
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Movable
|
Loading…
Reference in a new issue