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AC,UAAA,IAAI,EAAI;;;;;AAKnB,UAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE;UACtB,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,EAAE;;;;AAAC,AAIpB,UAAI,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;AAC1C,YAAM,CAAC,CAAC,GAAG,CAAC,CAAC;AACb,YAAM,CAAC,CAAC,GAAG,CAAC;;;;;AAAC,AAKb,wBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KACjC,CAAC,CAAC;GACJ,CAAC;CACH","file":"shortestPath.js","sourcesContent":["/*\nA demonstration of how to use Hexi's `shortestPath` function to help you find\nthe shortest path between two index points in a map array\n*/\n\n\nlet thingsToLoad = [\n \"images/timeBombPanic.png\",\n \"maps/AStar.json\"\n];\n\n//Create a new Hexi instance, and start it.\nlet g = hexi(832, 768, setup, thingsToLoad);\n\n//Set the background color and scale the canvas\n//g.backgroundColor = \"black\";\ng.scaleToWindow();\n\n//Start Hexi\ng.start();\n\n//Game variables\nlet alien, bomb, currentPath, world, wallMapArray, currentPathSprites;\n\n//The `setup` function to initialize your application\nfunction setup() {\n\n //Make the world from the Tiled JSON data and the tileset PNG image\n world = g.makeTiledWorld(\n \"maps/AStar.json\",\n \"images/timeBombPanic.png\"\n );\n\n //Create the alien sprite \n alien = world.getObject(\"alien\");\n\n //Create the bomb sprite\n //bomb = world.getObject(\"bomb\");\n\n //Get a reference to the array that stores all the wall data\n wallMapArray = world.getObject(\"wallLayer\").data;\n\n //An array to store the sprites that will be used to display \n //the shortest path \n currentPathSprites = [];\n\n //The mouse pointer's `release` function runs the code that\n //calculates the shortest path and draws that sprites that\n //represent it\n g.pointer.release = () => {\n\n //calculate the shortest path\n let path = g.shortestPath(\n g.getIndex(alien.x, alien.y, 64, 64, 13), //The start map index\n g.getIndex(g.pointer.x, g.pointer.y, 64, 64, 13), //The destination index\n wallMapArray, //The map array\n 13, //Map width, in tiles\n [2, 3], //Obstacle gid array\n \"manhattan\", //Heuristic to use\n true //Either use all diagonal nodes (true) or orthagonally adjacent nodes (false)\n );\n\n //Use Hexi's `remove` method to remove any possible \n //sprites in the `currentPathSprites` array\n g.remove(currentPathSprites);\n\n //Display the shortest path\n path.forEach(node => {\n\n //Figure out the x and y location of each square in the path by\n //multiplying the node's `column` and `row` by the height, in\n //pixels, of each square: 64 \n let x = node.column * 64,\n y = node.row * 64;\n\n //Create the square sprite and set it to the x and y location\n //we calculated above\n let square = g.rectangle(64, 64, \"black\");\n square.x = x;\n square.y = y;\n\n //Push the sprites into the `currentPath` array,\n //so that we can easily remove them the next time\n //the mouse is clicked\n currentPathSprites.push(square);\n });\n };\n}\n\n"]}