fix diagonal movement
This commit is contained in:
parent
df22b9ea3f
commit
3373e367ac
@ -38,7 +38,8 @@ end
|
|||||||
function logic:update(dt)
|
function logic:update(dt)
|
||||||
if self.state == "run" and self.mapLogic.runTarget then
|
if self.state == "run" and self.mapLogic.runTarget then
|
||||||
local delta = love.timer.getTime() - self.mapLogic.t0 or love.timer.getTime()
|
local delta = love.timer.getTime() - self.mapLogic.t0 or love.timer.getTime()
|
||||||
local fraction = delta / 0.5 -- бежим одну клетку за 500 мс
|
local fraction = delta /
|
||||||
|
(0.5 * self.mapLogic.runTarget:subtract(self.mapLogic.position):length()) -- бежим одну клетку за 500 мс, по диагонали больше
|
||||||
if fraction >= 1 then -- анимация перемещена завершена
|
if fraction >= 1 then -- анимация перемещена завершена
|
||||||
self.mapLogic.position = self.mapLogic.runTarget
|
self.mapLogic.position = self.mapLogic.runTarget
|
||||||
if not self.mapLogic.path:is_empty() then -- еще есть, куда бежать
|
if not self.mapLogic.path:is_empty() then -- еще есть, куда бежать
|
||||||
|
|||||||
4
main.lua
4
main.lua
@ -74,9 +74,9 @@ function love.draw()
|
|||||||
local mpos = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
local mpos = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() }):floor()
|
||||||
local path = (require "lib.pathfinder")(charPos, mpos)
|
local path = (require "lib.pathfinder")(charPos, mpos)
|
||||||
|
|
||||||
love.graphics.setColor(1, 0, 0)
|
love.graphics.setColor(0.6, 0.75, 0.5)
|
||||||
for p in path:values() do
|
for p in path:values() do
|
||||||
love.graphics.rectangle("fill", p.x + 0.45, p.y + 0.45, 0.1, 0.1)
|
love.graphics.circle("fill", p.x + 0.45, p.y + 0.45, 0.1)
|
||||||
end
|
end
|
||||||
love.graphics.setColor(1, 1, 1)
|
love.graphics.setColor(1, 1, 1)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user