fix: don't hardcode directions

This commit is contained in:
Kazhnuz 2020-08-04 22:40:58 +02:00
parent fb9d86999f
commit a686baf089
5 changed files with 17 additions and 9 deletions

View file

@ -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

View file

@ -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

View file

@ -9,7 +9,6 @@ function Ennemy:new(world, x, y, owner)
self.actionPerTurn = 2
self:initSprite()
self.direction = -1
end
function Ennemy:draw()

View file

@ -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

View file

@ -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