Last active
December 11, 2015 00:19
-
-
Save McFunkypants/4516039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handle click events on the canvas | |
function canvasClick(e) | |
{ | |
var x; | |
var y; | |
// grab html page coords | |
if (e.pageX != undefined && e.pageY != undefined) | |
{ | |
x = e.pageX; | |
y = e.pageY; | |
} | |
else | |
{ | |
x = e.clientX + document.body.scrollLeft + | |
document.documentElement.scrollLeft; | |
y = e.clientY + document.body.scrollTop + | |
document.documentElement.scrollTop; | |
} | |
// make them relative to the canvas only | |
x -= canvas.offsetLeft; | |
y -= canvas.offsetTop; | |
// return tile x,y that we clicked | |
var cell = | |
[ | |
Math.floor(x/tileWidth), | |
Math.floor(y/tileHeight) | |
]; | |
// now we know while tile we clicked | |
console.log('we clicked tile '+cell[0]+','+cell[1]); | |
pathStart = pathEnd; | |
pathEnd = cell; | |
// calculate path | |
currentPath = findPath(world,pathStart,pathEnd); | |
redraw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment