HTML and CSS Reference
In-Depth Information
Figure 8-9. The tiles sheet for the A* examples
Hereisthefullcodelistingfor Example 8-13 . Wewillbemodifyingthiscodeinthefollowing
sections to add to the size ofthe map and to demonstrate further A*functionality.This simple
example shows the basics of using the algorithm with our tile sheet and tile map and shows
how to display the results on the Canvas.
Example 8-13. A* Example 1
<!doctype html>
<html
<html lang= "en" >
<head>
<head>
<meta
<meta charset= "UTF-8" >
<title>
<title> Chapter 8 Example 14: A* Example 1 </title>
</title>
< script src = "modernizr.js" >< /script>
< script type = 'text/javascript' src = 'graph.js' >< /script>
< script type = 'text/javascript' src = 'astar.js' >< /script>
< script type = "text/javascript" >
window . addEventListener ( 'load' , eventWindowLoaded , false
false );
function
function eventWindowLoaded () {
canvasApp ();
}
function
function canvasSupport () {
return
return Modernizr . canvas ;
}
function
function canvasApp (){
iif ( ! canvasSupport ()) {
return
return ;
} else
else {
var
var theCanvas = document . getElementById ( 'canvas' );
var
var context = theCanvas . getContext ( '2d' );
}
//set up tile map
var
var mapRows = 5 ;
var
var mapCols = 5 ;
var
var tileMap = [
[ 0 , 1 , 0 , 0 , 0 ]
,[ 0 , 1 , 0 , 0 , 0 ]
Search WWH ::




Custom Search