topical media & game development

talk show tell print

mobile-query-three-plugins-simplemaze-examples-pathfinding.htm / htm



  <!doctype html><title>Minimal tQuery Page</title>
  <script src="../../../build/tquery-bundle.js"></script>
  
  <script src="../tquery.simplemaze.js"></script>
  
  <script src="../tquery.simplemaze.pathfinding.js"></script>
  <script src="../vendor/pathfinding-browser.js"></script>
  <body><script>
          var world        = tQuery.createWorld().boilerplate().start();
          var object	= tQuery.createTorus().addTo(world);
  
          var maze        = new tQuery.SimpleMaze({
                  map        : [
                          '*********',
                          '*   *   *',
                          '*  ** ***',
                          '*       *',
                          '***     *',
                          '*       *',
                          '*********'
                  ]
          });
          maze.addTo(world);
  
          // setup the path finding
          var pathFinding        = new tQuery.SimpleMazePathFinding({
                  maze        : maze
          });
  
          // establish some source/destination        
          var startX        = 7, startZ        = 1;
          //var startX        = 3, startZ        = 1;
          var endX        = 3, endZ        = 1;
          //var endX        = 1, endZ        = 5;
  
          // compute a path
          var source        = tQuery.createVector2(startX, startZ);
          var destination        = tQuery.createVector2(endX, endZ);
          pathFinding.computePath(source, destination);
  
          // draw the path on the screen - good for debug
          var path        = pathFinding.path();
          for(var i = 0; i < path.length; i++){
                  var position        = path[i];
                  var cube        = tQuery.createCube().addTo(world)
                          .scaleBy(0.5)
                          .translate(position.x, 0.25, position.z);
                  // set color of begining/end of the path
                  if( i === 0 )                        cube.setBasicMaterial().color(0xFF8080);
                  if( i === path.length-1 )        cube.setBasicMaterial().color(0x80FF80);
          }        
  </script></body>


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.