So is there any way to get perfectly rounded numbers for movement with delta time.
Here is the current code:
Code: Select all
function love.load()
player = {
x = 0,
y = 0,
targetY = 0,
targetX = 0,
w = 16,
h = 16,
moving = false
}
end
function love.update(dt)
local left = love.keyboard.isDown("left")
local right = love.keyboard.isDown("right")
local up = love.keyboard.isDown("up")
local down = love.keyboard.isDown("down")
-- remove * dt to see the super quick movement
if player.targetX > player.x then player.x = player.x + 4 * dt end
if player.targetX < player.x then player.x = player.x - 4 * dt end
if player.targetY > player.y then player.y = player.y + 4 * dt end
if player.targetY < player.y then player.y = player.y - 4 * dt end
if player.targetX == player.x and player.targetY == player.y then
player.moving = false
end
if left and not player.moving then
player.moving = true
player.targetX = player.targetX - 16
end
if right and not player.moving then
player.moving = true
player.targetX = player.targetX + 16
end
if up and not player.moving then
player.moving = true
player.targetY = player.targetY - 16
end
if down and not player.moving then
player.moving = true
player.targetY = player.targetY + 16
end
end
function love.draw()
--love.graphics.scale(2)
love.graphics.print(player.x, 0,0)
love.graphics.print(player.y, 0, 10)
love.graphics.rectangle("fill", player.x, player.y, player.w, player.h)
end