private void update() {

    // Did an invader bump into the side of the screen
    boolean bumped = false;

    // Has the player lost
    boolean lost = false;

    // Move the player's ship
    playerShip.update(fps);

    // Update the invaders if visible

    // Update the players bullet
    if (bullet.getStatus()) {
      bullet.update(fps);
    }

    // Update all the invaders bullets if active
    for (int i = 0; i < invadersBullets.length; i++) {
      if (invadersBullets[i].getStatus()) {
        invadersBullets[i].update(fps);
      }
    }

    // Update all the invaders if visible
    for (int i = 0; i < numInvaders; i++) {
      if (invaders[i].getVisibility()) {

        // Move the next invader
        invaders[i].update(fps);

        // Does he want to take a shot?
        if (invaders[i].takeAim(playerShip.getX(), playerShip.getLength())) {

          // If so try and spawn a bullet
          if (invadersBullets[nextBullet].shoot(
              invaders[i].getX() + invaders[i].getLength() / 2, invaders[i].getY(), bullet.DOWN)) {

            // Shot fired
            // Prepare for the next shot
            nextBullet++;

            // Loop back to the first one if we have reached the last
            if (nextBullet == maxInvaderBullets) {
              // This stops the firing of another bullet until one completes its journey
              // Because if bullet 0 is still active shoot returns false.
              nextBullet = 0;
            }
          }
        }

        // If that move caused them to bump the screen change bumped to true
        if (invaders[i].getX() > screenX - invaders[i].getLength() || invaders[i].getX() < 0) {

          bumped = true;
        }
      }
    }

    // Did an invader bump into the edge of the screen
    if (bumped) {
      // Move all the invaders down and change direction
      for (int i = 0; i < numInvaders; i++) {
        invaders[i].dropDownAndReverse();

        // Have the invaders landed
        if (invaders[i].getY() > screenY - screenY / 10) {
          lost = true;
        }
      }

      // Increase the menace level
      // By making the sounds more frequent
      menaceInterval = menaceInterval - 80;
    }

    if (lost) {
      prepareLevel();
    }

    // Has the player's bullet hit the top of the screen
    if (bullet.getImpactPointY() < 0) {
      bullet.setInactive();
    }

    // Has an invaders bullet hit the bottom of the screen
    for (int i = 0; i < invadersBullets.length; i++) {

      if (invadersBullets[i].getImpactPointY() > screenY) {
        invadersBullets[i].setInactive();
      }
    }

    // Has the player's bullet hit an invader
    if (bullet.getStatus()) {
      for (int i = 0; i < numInvaders; i++) {
        if (invaders[i].getVisibility()) {
          if (RectF.intersects(bullet.getRect(), invaders[i].getRect())) {
            invaders[i].setInvisible();
            soundPool.play(invaderExplodeID, 1, 1, 0, 0, 1);
            bullet.setInactive();
            score = score + 10;

            // Has the player won

            if (score == numInvaders * 10) {
              paused = true;
              String mScore = score + "";
              Log.d("Score: ", mScore);
              Context context = getContext();
              Intent intent = new Intent(context, ScoreActivity.class);
              intent.putExtra("score", mScore);
              context.startActivity(intent);
            }
          }
        }
      }
    }

    // Has an alien bullet hit a shelter brick
    for (int i = 0; i < invadersBullets.length; i++) {
      if (invadersBullets[i].getStatus()) {
        for (int j = 0; j < numBricks; j++) {
          if (bricks[j].getVisibility()) {
            if (RectF.intersects(invadersBullets[i].getRect(), bricks[j].getRect())) {
              // A collision has occurred
              invadersBullets[i].setInactive();
              bricks[j].setInvisible();
              soundPool.play(damageShelterID, 1, 1, 0, 0, 1);
            }
          }
        }
      }
    }

    // Has a player bullet hit a shelter brick
    if (bullet.getStatus()) {
      for (int i = 0; i < numBricks; i++) {
        if (bricks[i].getVisibility()) {
          if (RectF.intersects(bullet.getRect(), bricks[i].getRect())) {
            // A collision has occurred
            bullet.setInactive();
            bricks[i].setInvisible();
            soundPool.play(damageShelterID, 1, 1, 0, 0, 1);
          }
        }
      }
    }

    // Has an invader bullet hit the player ship
    for (int i = 0; i < invadersBullets.length; i++) {
      if (invadersBullets[i].getStatus()) {
        if (RectF.intersects(playerShip.getRect(), invadersBullets[i].getRect())) {
          invadersBullets[i].setInactive();
          lives--;
          soundPool.play(playerExplodeID, 1, 1, 0, 0, 1);

          // Is it game over?
          if (lives == 0) {
            paused = true;
            //                        lives = 3;
            //                        score = 0;
            String mScore = score + "";
            Context context = getContext();
            Intent intent = new Intent(context, ScoreActivity.class);
            intent.putExtra("score", mScore);
            context.startActivity(intent);

            //                        prepareLevel();

          }
        }
      }
    }
  }