From a686baf089752aa16349250ccc49f30320889c11 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 4 Aug 2020 22:40:58 +0200 Subject: [PATCH] fix: don't hardcode directions --- sonic-radiance.love/core/utils/math.lua | 2 +- .../scenes/battlesystem/actors/battler.lua | 5 +++++ .../scenes/battlesystem/actors/ennemy.lua | 1 - .../scenes/battlesystem/actors/hero.lua | 10 ++++++---- .../fighters/systems/choregraphy/step/parent.lua | 8 +++++--- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sonic-radiance.love/core/utils/math.lua b/sonic-radiance.love/core/utils/math.lua index d108567..6b6624c 100644 --- a/sonic-radiance.love/core/utils/math.lua +++ b/sonic-radiance.love/core/utils/math.lua @@ -94,7 +94,7 @@ function Math.pointDirection(x1,y1,x2,y2) local vecx, vecy, angle vecy = y2 - y1 vecx = x2 - x1 - angle = math.atan2(vecy, vecx) + angle = math.atan2(-vecy, vecx) return angle end diff --git a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua index 12b67b9..db41947 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua @@ -1,12 +1,17 @@ local Parent = require("scenes.battlesystem.actors.parent") local Battler = Parent:extend() +local MIDDLE_ARENA = 6 + function Battler:new(world, x, y, z, owner) Battler.super.new(self, world, x, y, z) + self.direction = utils.math.sign(MIDDLE_ARENA - x) + self.start = {} self.start.x = x self.start.y = y + self.start.direction = self.direction self.isBattler = true self.speed = 3 diff --git a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua index 0b33a79..7317e6b 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua @@ -9,7 +9,6 @@ function Ennemy:new(world, x, y, owner) self.actionPerTurn = 2 self:initSprite() - self.direction = -1 end function Ennemy:draw() diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index de89448..3a76373 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -39,8 +39,8 @@ local MOVEMENT_DURATION = 0.20 function Hero:initMovementSystem() self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z self.xspeed, self.yspeed, self.zspeed = 0,0,0 - self.direction = 1 - self.directionPrevious = 1 + self.direction = self.start.direction + self.directionPrevious = self.start.direction self.directionLocked = false self.movementType = MOVEMENT_NONE @@ -143,7 +143,9 @@ end function Hero:jumpBack() self:setJump(3, 0, true) - self:setMotion(-10, 0) + local dir = utils.math.pointDirection(self.x, self.y, self.start.x, self.start.y) + local hspeed, vspeed = utils.math.lengthdir(10, dir) + self:setMotion(hspeed, vspeed) self.jump.isJumpingBack = true end @@ -195,7 +197,7 @@ function Hero:timerResponse(signal) end function Hero:choregraphyEnded() - self.direction = 1 + self.direction = self.start.direction self.x = self.start.x self.y = self.start.y self.xspeed = 0 diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua index 5e5508a..40d91c1 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/parent.lua @@ -16,16 +16,18 @@ function StepParent:updateStep(dt) end function StepParent:getStepCoordinate() + local argx, argy = self.arguments.x, self.arguments.y + argx = argx * self.choregraphy.actor.start.direction if (self.arguments.origin == "target") then local target = self.choregraphy.action.target local x, y = target.actor:getCoordinate() - return x + self.arguments.x, y + self.arguments.y + return x + argx, y + argy elseif (self.arguments.origin == "start") then local x, y = self.choregraphy.actor.start.x, self.choregraphy.actor.start.y - return x + self.arguments.x, y + self.arguments.y + return x + argx, y + argy elseif (self.arguments.origin == "actor") then local x, y = self.choregraphy.actor:getCoordinate() - return x + self.arguments.x, y + self.arguments.y + return x + argx, y + argy end end