fix diagonal movement
This commit is contained in:
parent
df22b9ea3f
commit
3373e367ac
@ -38,10 +38,11 @@ end
|
||||
function logic:update(dt)
|
||||
if self.state == "run" and self.mapLogic.runTarget then
|
||||
local delta = love.timer.getTime() - self.mapLogic.t0 or love.timer.getTime()
|
||||
local fraction = delta / 0.5 -- бежим одну клетку за 500 мс
|
||||
if fraction >= 1 then -- анимация перемещена завершена
|
||||
local fraction = delta /
|
||||
(0.5 * self.mapLogic.runTarget:subtract(self.mapLogic.position):length()) -- бежим одну клетку за 500 мс, по диагонали больше
|
||||
if fraction >= 1 then -- анимация перемещена завершена
|
||||
self.mapLogic.position = self.mapLogic.runTarget
|
||||
if not self.mapLogic.path:is_empty() then -- еще есть, куда бежать
|
||||
if not self.mapLogic.path:is_empty() then -- еще есть, куда бежать
|
||||
self:runTo(self.mapLogic.path:peek_front())
|
||||
self.mapLogic.path:pop_front()
|
||||
else -- мы добежали до финальной цели
|
||||
|
||||
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 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
|
||||
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
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user