Hello, I did a quick check on your code. I understood now what you wanted. Yes, since the turn movement isn't over but player already did another key movement then the dt based animation update tries to compensate accelerating the player movement to the now distant place.
Code: Select all
-- teehee
require("lib/AnAL")
function love.load()
-- Sprite map
ayla_img = love.graphics.newImage("assets/ayla.png")
-- Textures
grass = love.graphics.newImage("assets/grass.png")
stone = love.graphics.newImage("assets/stone.png")
-- Animation
local function newAnim(img, offset, frames)
local anim = newAnimation(img, 32, 32, 0.125, 1)
anim.frames = {}
for i=0,frames-1 do
anim:addFrame(i*32, offset*32, 32, 32, 0.125)
end
return anim
end
ayla = {
down = newAnim(ayla_img, 0, 7),
left = newAnim(ayla_img, 1, 7),
right= newAnim(ayla_img, 1, 7),
up = newAnim(ayla_img, 2, 7),
}
current = "down"
--anim:setMode("once")
-- Player array
player = {
grid_x = 256,
grid_y = 256,
real_x = 256,
real_y = 256,
speed = 5,
control = true
}
-- Map array
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
}
end
-- dt = delta time
function love.update(dt)
anim = ayla[current]
player.real_y = player.real_y - ((player.real_y - player.grid_y) * player.speed * dt)
player.real_x = player.real_x - ((player.real_x - player.grid_x) * player.speed * dt)
if math.abs(player.grid_x - player.real_x) < 1 then
player.real_x = player.grid_x
end
if math.abs(player.grid_y - player.real_y) < 1 then
player.real_y = player.grid_y
end
if player.real_x == player.grid_x and player.real_y == player.grid_y then player.control = true end
anim:update(dt)
end
-- # = "number of things in this" aka count
function love.draw()
for y = 1, #map do
for x = 1, #map[y] do
if map[y][x] == 1 then
love.graphics.draw(stone, x * 32, y * 32, 0, 1, 1, 0, 0, 0, 0)
else
love.graphics.draw(grass, x * 32, y * 32, 0, 1, 1, 0, 0, 0, 0)
end
end
end
if current == "right" then
anim:draw(player.real_x, player.real_y, 0, -1, 1, 32, 0)
else
anim:draw(player.real_x, player.real_y)
end
love.graphics.print ("G_X:"..player.grid_x.." G_Y:"..player.grid_y.." X:"..player.real_x.." Y:"..player.real_y.." "..tostring(player.control),0,0)
end
function love.keypressed(key)
if key == "escape" then
love.event.push("quit")
end
if key == "up" and player.control then
current = key
if testMap(0, -1) then
player.grid_y = player.grid_y - 32
player.control = false
end
end
if key == "down" and player.control then
current = key
if testMap(0, 1) then
player.grid_y = player.grid_y + 32
player.control = false
end
end
if key == "left" and player.control then
current = key
if testMap(-1, 0) then
player.grid_x = player.grid_x - 32
player.control = false
end
end
if key == "right" and player.control then
current = key
if testMap(1, 0) then
player.grid_x = player.grid_x + 32
player.control = false
end
end
end
function testMap(x, y)
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
return false
end
return true
end
If this still don't please you need then change instead dt formula.