Code: Select all
local a = (TILE_WIDTH / 2) -- a11
local b = -(TILE_WIDTH / 2) -- a12
local c = (TILE_WIDTH / 4) -- a21
local d = (TILE_WIDTH / 4) -- a22
function ToScreen(x, y, xtransform, ytransform)
xtransform = xtransform or 0
ytransform = ytransform or 0
local xx = (x * a + y * b) - TILE_WIDTH / 2
local yy = (x * c + y * d) - TILE_HEIGHT / 2
return math.floor(xx + xtransform), math.floor(yy + ytransform)
end
function ToWorld(x, y)
local scalar = 1 / (a * d - b * c)
local aa = d * scalar
local bb = -b * scalar
local cc = -c * scalar
local dd = a * scalar
local xx = (x * aa + y * bb) + TILE_WIDTH / 2
local yy = (x * cc + y * dd) + TILE_HEIGHT / 2
return math.floor(xx), math.floor(yy)
end
Code: Select all
function love.draw()
love.graphics.scale(SCALE, SCALE)
for y = 0, ACTUAL_MAP_HEIGHT do
for x = 0, ACTUAL_MAP_WIDTH do
local tile_index = Map:GetIndexFromXY(x, y)
local tile = Map[tile_index]
light_color = tile.color
love.graphics.setColor(light_color)
local xx, yy = ToScreen(x, y, WINDOW_WIDTH / 2, WINDOW_HIEGHT / 4)
love.graphics.draw(sheet, tilemap[tile.tileset], xx, yy)
end
end
end
function love.update()
print(ToWorld(love.mouse.getPosition()))
end
https://github.com/Caue-Aron/Isometric