function update(delta, timeElapsed) {
  player.update();
  player.collideSolid(solid);
  // Parallax
  hills.scroll(player.x - player.lastX, 0);
  hills2.scroll(player.x - player.lastX, 0);

  enemies.forEach(function(enemy) {
    // Reverse if we get to the edge of a platform.
    if (!enemy.standingOn(solid) &&
        (!enemy.STAY_IN_WORLD || enemy.y != world.height - enemy.height)) {
      enemy.reverse();
    }
    enemy.update();
    // Reverse if we run into a wall.
    if (enemy.collideSolid(solid).x) {
      enemy.reverse();
    }
    // Reverse if we run into the side of the world.
    else if (enemy.STAY_IN_WORLD &&
        (enemy.x < 0 || enemy.x + enemy.width >= world.width)) {
      enemy.reverse();
    }
    // The player dies if it touches an enemy.
    if (enemy.collides(player)) {
      App.gameOver();
    }
  });

  bullets.forEach(function(bullet) {
    bullet.update();
    // Shoot enemies.
    var enemy = bullet.collides(enemies);
    if (enemy) {
      player.increaseScore(10);
      enemies.remove(enemy);
      enemy.destroy();
    }
    // Returning true removes the bullet from the Collection and destroy()s it.
    // This destroys the bullet if it hits a solid or goes out of the world.
    return enemy || bullet.collides(solid) || !world.isInWorld(bullet, true);
  });

  coins.forEach(function(coin) {
    if (player.overlaps(coin)) {
      player.increaseScore(1);
      return true;
    }
  });

  if (castle.overlaps(player)) {
    App.gameOver("YOU WIN!");
  }
}
/**
 * A magic-named function where all updates should occur.
 *
 * @param {Number} delta
 *   The amount of time since the last update. Use this to smooth movement.
 *   This has the same value as the global App.physicsDelta.
 * @param {Number} timeElapsed
 *   The amount of time elapsed while animating. This is useful for time-based
 *   movement and limiting the frequency of events. This has the same value as
 *   the global App.physicsTimeElapsed.
 */
A magic-named function where all updates should occur.
@param {Number} delta
The amount of time since the last update. Use this to smooth movement.
This has the same value as the global App.physicsDelta.
@param {Number} timeElapsed
The amount of time elapsed while animating. This is useful for time-based
movement and limiting the frequency of events. This has the same value as
the global App.physicsTimeElapsed.
A magic - named function where all updates should occur . @param { Number } delta The amount of time since the last update . Use this to smooth movement . This has the same value as the global App . physicsDelta . @param { Number } timeElapsed The amount of time elapsed while animating . This is useful for time - based movement and limiting the frequency of events . This has the same value as the global App . physicsTimeElapsed .
function update(delta, timeElapsed) {
  player.update();
  player.collideSolid(solid);
  hills.scroll(player.x - player.lastX, 0);
  hills2.scroll(player.x - player.lastX, 0);
  enemies.forEach(function(enemy) {
    if (!enemy.standingOn(solid) &&
        (!enemy.STAY_IN_WORLD || enemy.y != world.height - enemy.height)) {
      enemy.reverse();
    }
    enemy.update();
    if (enemy.collideSolid(solid).x) {
      enemy.reverse();
    }
    else if (enemy.STAY_IN_WORLD &&
        (enemy.x < 0 || enemy.x + enemy.width >= world.width)) {
      enemy.reverse();
    }
    if (enemy.collides(player)) {
      App.gameOver();
    }
  });
  bullets.forEach(function(bullet) {
    bullet.update();
    var enemy = bullet.collides(enemies);
    if (enemy) {
      player.increaseScore(10);
      enemies.remove(enemy);
      enemy.destroy();
    }
    return enemy || bullet.collides(solid) || !world.isInWorld(bullet, true);
  });
  coins.forEach(function(coin) {
    if (player.overlaps(coin)) {
      player.increaseScore(1);
      return true;
    }
  });
  if (castle.overlaps(player)) {
    App.gameOver("YOU WIN!");
  }
}
function update ( delta , timeElapsed ) { player . update ( ) ; player . collideSolid ( solid ) ; hills . scroll ( player . x - player . lastX , 0 ) ; hills2 . scroll ( player . x - player . lastX , 0 ) ; enemies . forEach ( function ( enemy ) { if ( ! enemy . standingOn ( solid ) && ( ! enemy . STAY_IN_WORLD || enemy . y != world . height - enemy . height ) ) { enemy . reverse ( ) ; } enemy . update ( ) ; if ( enemy . collideSolid ( solid ) . x ) { enemy . reverse ( ) ; } else if ( enemy . STAY_IN_WORLD && ( enemy . x < 0 || enemy . x + enemy . width >= world . width ) ) { enemy . reverse ( ) ; } if ( enemy . collides ( player ) ) { App . gameOver ( ) ; } } ) ; bullets . forEach ( function ( bullet ) { bullet . update ( ) ; var enemy = bullet . collides ( enemies ) ; if ( enemy ) { player . increaseScore ( 10 ) ; enemies . remove ( enemy ) ; enemy . destroy ( ) ; } return enemy || bullet . collides ( solid ) || ! world . isInWorld ( bullet , true ) ; } ) ; coins . forEach ( function ( coin ) { if ( player . overlaps ( coin ) ) { player . increaseScore ( 1 ) ; return true ; } } ) ; if ( castle . overlaps ( player ) ) { App . gameOver ( "YOU WIN!" ) ; } }
A magic-named function where all updates should occur.
A magic - named function where all updates should occur .
// Parallax // Reverse if we get to the edge of a platform. // Reverse if we run into a wall. // Reverse if we run into the side of the world. // The player dies if it touches an enemy. // Shoot enemies. // Returning true removes the bullet from the Collection and destroy()s it. // This destroys the bullet if it hits a solid or goes out of the world.