コード例 #1
0
  public void moveProjectile() {
    // if the player's shot exists
    if (playerProj.isVisible()) {
      playerProj.setPositionY(playerProj.getPositionY() - 5);
      // Move it down (higher edge of the screen)
      playerProj.setLocation(playerProjX, playerProj.getPositionY());
      // Check for hit
      checkForHit();
    }

    if (playerProj.getPositionY() <= ceiling.getLocation().getY() + 5) {
      playerProj.setVisible(false);
    }
    checkForHit();
  }
コード例 #2
0
  public void checkForHit() {

    for (int y = 0; y < 4; y++) {
      for (int x = 0; x < 10; x++) {
        if (enemies[y][x].getBounds().contains(playerProjX, playerProj.getPositionY())
            && playerProj.isVisible()
            && enemies[y][x].isVisible()) {
          // loop through enemies, if they have the projectile in
          // them, destroy them and the shot
          playerProj.setVisible(false);
          score += enemies[y][x].damage();
          updateLabels();
        }
      }
    }

    checkForWin();

    for (int i = 0; i < projectileAmount; i++) {
      if (player.getBounds().contains(enemyProjX[i], enemyProj[i].getPositionY())
          && player.isVisible()
          && enemyProj[i].isVisible()) {
        enemyProj[i].setVisible(false);
        player.setVisible(false);
        if (lives != -1) {
          livesImages[lives].setVisible(false);
        } else {
          // Player loses, lives = -1
          loss();
        }
      }
    }
  }