-- example 1 local d = math.sqrt((x - x2)^2 + (y - y2)^2) local nx, ny = (x - x2)/d, (y - y2)/d
-- example 2 local dx, dy = x - x2, y - y2 local dsq = dx^2 + dy^2 local d = math.sqrt(dsq) local nx, ny = dx/d, dy/d
-- example 1 if up then player:move(0, 10) elseif down then player:move(0, -10) end if right then player:move(10, 0) elseif left then player:move(-10, 0) end
-- example 2 local dx, dy = 0, 0 if up then dy = 10 elseif down then dy = -10 else if right then dx = 10 elseif left then dx = -10 end if dx ~= 0 or dy ~= 0 then player:move(dx, dy) end
-- if then solution local x = tx*tile_width if ty%2 == 1 then x = x + tile_width/2 end local y = ty*tile_height/2
-- math solution local x_offset = ty%2*(tile_width/2) local x = tx*tile_width + x_offset local y = ty*(tile_height/2)
-- example 1 player.get_position = function(player) return { x = player.x, y = player.y } end
-- example 2 player.get_position = function(player) return player.x, player.y end