Beispiel #1
0
 public void takeDamage() {
   if (!hurtAnimating) {
     if (user.getHealth() == 0) gameOver = true;
     else {
       hurtAnimating = true;
       user.setHealth(user.getHealth() - 1);
       healthHandLabel[user.getHealth()].setVisible(false);
       hurtAnimation();
     }
   }
 }
Beispiel #2
0
  public void playLevel(int level) { // Run the game
    System.out.println("Starting level " + level);
    onTitleScreen = false;
    toBeKilled = 100; // Game is intended to be run at 100
    timer = 0;
    onScreen = 0;

    // Updates level information and saves to User
    currentLevel = level;
    if (currentLevel > user.getMaxLevel()) user.setMaxLevel(currentLevel);
    Data.save(user);

    // Making appropriate adjustments to game screen
    backgroundLabel.setIcon(backgroundIcon[(currentLevel - 1) % 3 + 1]);

    counterLabel[0].setIcon(counterIcon[1]);
    counterLabel[1].setIcon(counterIcon[0]);
    counterLabel[2].setIcon(counterIcon[0]);

    for (int i = 0; i < counterLabel.length; i++) counterLabel[i].setVisible(true);
    for (int i = 0; i < user.getHealth(); i++) // Adjust health hands accordingly
    healthHandLabel[i].setVisible(true);

    // Switch to game cursor
    menuCursorLabel.setVisible(false);
    gameCursorLabel.setVisible(true);

    new Thread(
            new Runnable() {
              public void run() {
                try {
                  Thread.currentThread().sleep(500);
                  music.playLevelMusic(
                      (currentLevel - 1) % 3 + 1); // First three songs continuously looped
                  Thread.currentThread().sleep(2500);
                  while (toBeKilled > 0) { // Level is over when all are dead
                    if (gameOver) {
                      gameOver();
                      return;
                    }
                    if (onScreen < 2 * ((currentLevel - 1) % 3 + 1)
                        && timer > 10
                        && (onScreen % 20 != toBeKilled % 20
                            || onScreen == 0)) { // Limits number on screen and when they appear
                      onScreen++;
                      timer = (int) Math.round(Math.random() * 5);

                      if (toBeKilled > 80) createBug(SMALLFLY);
                      else if (toBeKilled > 60) {
                        if (Math.random() > .6) createBug(SMALLFLY);
                        else createBug(BLUEFLY);
                      } else if (toBeKilled > 40) {
                        if (Math.random() > .6) createBug(SMALLFLY);
                        else createBug(WASP);
                      } else if (toBeKilled > 20) {
                        createBug(BLUEFLY);
                      } else {
                        if (Math.random() > .5) createBug(WASP);
                        else createBug(BLUEFLY);
                      }
                    }
                    for (int j = 0; j < aLabel.size(); j++) aLabel.get(j).step();
                    Thread.currentThread().sleep(40);
                    timer++;
                  }
                } catch (Exception exc) {
                }
                if (!gameOver) {
                  System.out.println("Level beaten.  Moving to next level.");
                  music.stop();
                  clearScreen();
                  playLevel(currentLevel + 1);
                }
              }
            })
        .start();
  }