I have a Tilemap written in plain JavaScript:
const map = [
0,0,1,1,
1,1,1,1,
1,1,1,1,
1,1,1,1
]
Each tile is rendered as 128*128px square.
And I have written a function that prints out the euclidean distance between two points, in my case the distance between a click event on the tile map:
function distance(x,y,x2,y2) {
return Math.sqrt(Math.pow((x-x2), 2)+Math.pow((y-y2), 2))
}
How do I calculate on which of the tiles the click occured?