From a2b24e39631675f223322ff13948f0eb899db206 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 24 Aug 2019 16:13:22 +0200 Subject: [PATCH] feat(cbs): add a jump system --- .../scenes/battlesystem/actors/hero.lua | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index ce3dc57..0ec2a75 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -12,7 +12,7 @@ function Hero:new(world, x, y, charid, charnumber) self:initMovementSystem() - self:initCharacter() + self:initCharacter(charid) self:initSprite() self:initChoregraphySystem() @@ -111,14 +111,22 @@ function Hero:initMovementSystem() self.xprevious, self.yprevious = self.x, self.y self.direction = 1 self.directionPrevious = 1 + + self:initJump() end -function Hero:goTo(dx, dy, timerName) - local DURATION = 0.66 - self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'inQuad') +function Hero:goTo(dx, dy, timerName, duration) + local DURATION = duration or 0.66 + self.tweens:newTween(0, DURATION, {x = dx, y = dy}, 'linear') self.tweens:newTimer(DURATION + 0.02, timerName) 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) self.xspeed = self.x - self.xprevious self.yspeed = self.y - self.yprevious @@ -142,6 +150,18 @@ function Hero:changeDirection(dt) 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 -- All functions related to signal receiving @@ -353,9 +373,7 @@ end -- Draw everything related to the hero function Hero:draw() - x, y = self.maputils.gridToPixel(self.x, self.y, true) - --love.graphics.rectangle("fill", x - 8, y - 32, 16, 32) - self:drawSprite() + self:drawSprite(0, -self.z) end function Hero:drawIcon(x, y)