example/Asteroid.js
function addAsteroids() {
    while (asteroidBodies.length) {
      var asteroidBody = asteroidBodies.shift();
      world.destroyBody(asteroidBody);
      // asteroidBody.uiRemove();
    }

    for (var i = 0; i < level; i++) {
      var shipPosition = shipBody.getPosition();
      var x = shipPosition.x;
      var y = shipPosition.y;

      // Aviod the ship!
      while (Math.abs(x - shipPosition.x) < asteroidRadius * 2
          && Math.abs(y - shipPosition.y) < asteroidRadius * 2) {
        x = rand(SPACE_WIDTH);
        y = rand(SPACE_HEIGHT);
      }

      var vx = rand(asteroidSpeed);
      var vy = rand(asteroidSpeed);
      var va = rand(asteroidSpeed);

      // Create asteroid body
      var asteroidBody = makeAsteroidBody(x, y, vx, vy, va, 0);
      asteroidBody.level = 1;
    }
  }
function addAsteroids() {
    while (asteroidBodies.length) {
      var asteroidBody = asteroidBodies.shift();
      world.destroyBody(asteroidBody);
      // asteroidBody.uiRemove();
    }

    for (var i = 0; i < level; i++) {
      var shipPosition = shipBody.getPosition();
      var x = shipPosition.x;
      var y = shipPosition.y;

      // Aviod the ship!
      while (Math.abs(x - shipPosition.x) < asteroidRadius * 2
          && Math.abs(y - shipPosition.y) < asteroidRadius * 2) {
        x = rand(SPACE_WIDTH);
        y = rand(SPACE_HEIGHT);
      }

      var vx = rand(asteroidSpeed);
      var vy = rand(asteroidSpeed);
      var va = rand(asteroidSpeed);

      // Create asteroid body
      var asteroidBody = makeAsteroidBody(x, y, vx, vy, va, 0);
      asteroidBody.level = 1;
    }
  }
function addAsteroids ( ) { while ( asteroidBodies . length ) { var asteroidBody = asteroidBodies . shift ( ) ; world . destroyBody ( asteroidBody ) ; // asteroidBody.uiRemove(); } for ( var i = 0 ; i < level ; i ++ ) { var shipPosition = shipBody . getPosition ( ) ; var x = shipPosition . x ; var y = shipPosition . y ; // Aviod the ship! while ( Math . abs ( x - shipPosition . x ) < asteroidRadius * 2 && Math . abs ( y - shipPosition . y ) < asteroidRadius * 2 ) { x = rand ( SPACE_WIDTH ) ; y = rand ( SPACE_HEIGHT ) ; } var vx = rand ( asteroidSpeed ) ; var vy = rand ( asteroidSpeed ) ; var va = rand ( asteroidSpeed ) ; // Create asteroid body var asteroidBody = makeAsteroidBody ( x , y , vx , vy , va , 0 ) ; asteroidBody . level = 1 ; } }
Adds some asteroids to the scene.
Adds some asteroids to the scene .