fix: don't hardcode directions
This commit is contained in:
parent
fb9d86999f
commit
a686baf089
5 changed files with 17 additions and 9 deletions
|
@ -94,7 +94,7 @@ function Math.pointDirection(x1,y1,x2,y2)
|
||||||
local vecx, vecy, angle
|
local vecx, vecy, angle
|
||||||
vecy = y2 - y1
|
vecy = y2 - y1
|
||||||
vecx = x2 - x1
|
vecx = x2 - x1
|
||||||
angle = math.atan2(vecy, vecx)
|
angle = math.atan2(-vecy, vecx)
|
||||||
|
|
||||||
return angle
|
return angle
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
local Parent = require("scenes.battlesystem.actors.parent")
|
local Parent = require("scenes.battlesystem.actors.parent")
|
||||||
local Battler = Parent:extend()
|
local Battler = Parent:extend()
|
||||||
|
|
||||||
|
local MIDDLE_ARENA = 6
|
||||||
|
|
||||||
function Battler:new(world, x, y, z, owner)
|
function Battler:new(world, x, y, z, owner)
|
||||||
Battler.super.new(self, world, x, y, z)
|
Battler.super.new(self, world, x, y, z)
|
||||||
|
|
||||||
|
self.direction = utils.math.sign(MIDDLE_ARENA - x)
|
||||||
|
|
||||||
self.start = {}
|
self.start = {}
|
||||||
self.start.x = x
|
self.start.x = x
|
||||||
self.start.y = y
|
self.start.y = y
|
||||||
|
self.start.direction = self.direction
|
||||||
|
|
||||||
self.isBattler = true
|
self.isBattler = true
|
||||||
self.speed = 3
|
self.speed = 3
|
||||||
|
|
|
@ -9,7 +9,6 @@ function Ennemy:new(world, x, y, owner)
|
||||||
|
|
||||||
self.actionPerTurn = 2
|
self.actionPerTurn = 2
|
||||||
self:initSprite()
|
self:initSprite()
|
||||||
self.direction = -1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Ennemy:draw()
|
function Ennemy:draw()
|
||||||
|
|
|
@ -39,8 +39,8 @@ local MOVEMENT_DURATION = 0.20
|
||||||
function Hero:initMovementSystem()
|
function Hero:initMovementSystem()
|
||||||
self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z
|
self.xprevious, self.yprevious, self.zprevious = self.x, self.y, self.z
|
||||||
self.xspeed, self.yspeed, self.zspeed = 0,0,0
|
self.xspeed, self.yspeed, self.zspeed = 0,0,0
|
||||||
self.direction = 1
|
self.direction = self.start.direction
|
||||||
self.directionPrevious = 1
|
self.directionPrevious = self.start.direction
|
||||||
self.directionLocked = false
|
self.directionLocked = false
|
||||||
|
|
||||||
self.movementType = MOVEMENT_NONE
|
self.movementType = MOVEMENT_NONE
|
||||||
|
@ -143,7 +143,9 @@ end
|
||||||
|
|
||||||
function Hero:jumpBack()
|
function Hero:jumpBack()
|
||||||
self:setJump(3, 0, true)
|
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
|
self.jump.isJumpingBack = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -195,7 +197,7 @@ function Hero:timerResponse(signal)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:choregraphyEnded()
|
function Hero:choregraphyEnded()
|
||||||
self.direction = 1
|
self.direction = self.start.direction
|
||||||
self.x = self.start.x
|
self.x = self.start.x
|
||||||
self.y = self.start.y
|
self.y = self.start.y
|
||||||
self.xspeed = 0
|
self.xspeed = 0
|
||||||
|
|
|
@ -16,16 +16,18 @@ function StepParent:updateStep(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function StepParent:getStepCoordinate()
|
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
|
if (self.arguments.origin == "target") then
|
||||||
local target = self.choregraphy.action.target
|
local target = self.choregraphy.action.target
|
||||||
local x, y = target.actor:getCoordinate()
|
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
|
elseif (self.arguments.origin == "start") then
|
||||||
local x, y = self.choregraphy.actor.start.x, self.choregraphy.actor.start.y
|
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
|
elseif (self.arguments.origin == "actor") then
|
||||||
local x, y = self.choregraphy.actor:getCoordinate()
|
local x, y = self.choregraphy.actor:getCoordinate()
|
||||||
return x + self.arguments.x, y + self.arguments.y
|
return x + argx, y + argy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue