improvement: use a 360 motion system
This commit is contained in:
parent
4379f55f27
commit
8dd4e7ba62
1 changed files with 13 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue