feat(cbs): add a jump system

This commit is contained in:
Kazhnuz 2019-08-24 16:13:22 +02:00
parent c78aa214ae
commit a2b24e3963

View file

@ -12,7 +12,7 @@ function Hero:new(world, x, y, charid, charnumber)
self:initMovementSystem() self:initMovementSystem()
self:initCharacter() self:initCharacter(charid)
self:initSprite() self:initSprite()
self:initChoregraphySystem() self:initChoregraphySystem()
@ -111,14 +111,22 @@ function Hero:initMovementSystem()
self.xprevious, self.yprevious = self.x, self.y self.xprevious, self.yprevious = self.x, self.y
self.direction = 1 self.direction = 1
self.directionPrevious = 1 self.directionPrevious = 1
self:initJump()
end end
function Hero:goTo(dx, dy, timerName) function Hero:goTo(dx, dy, timerName, duration)
local DURATION = 0.66 local DURATION = duration or 0.66
self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'inQuad') self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'linear')
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)
local DURATION = duration or 0.66
self:goTo(dx, dy, timerName, DURATION)
self:setJump(size, spinjump, DURATION)
end
function Hero:updateSpeed(dt) function Hero:updateSpeed(dt)
self.xspeed = self.x - self.xprevious self.xspeed = self.x - self.xprevious
self.yspeed = self.y - self.yprevious self.yspeed = self.y - self.yprevious
@ -142,6 +150,18 @@ function Hero:changeDirection(dt)
end end
end end
function Hero:initJump()
self.jump = {}
self.jump.spin = false
end
function Hero:setJump(size, spinjump, duration)
local duration = duration or 0.66
local tweenDuration = duration / 2
self.tweens:newTween(0, tweenDuration, {z = size}, 'outQuad')
self.tweens:newTween(tweenDuration, tweenDuration, {z = 0}, 'inQuad')
end
-- SIGNAL FUNCTIONS -- SIGNAL FUNCTIONS
-- All functions related to signal receiving -- All functions related to signal receiving
@ -353,9 +373,7 @@ end
-- Draw everything related to the hero -- Draw everything related to the hero
function Hero:draw() function Hero:draw()
x, y = self.maputils.gridToPixel(self.x, self.y, true) self:drawSprite(0, -self.z)
--love.graphics.rectangle("fill", x - 8, y - 32, 16, 32)
self:drawSprite()
end end
function Hero:drawIcon(x, y) function Hero:drawIcon(x, y)