示例#1
0
  private void countdown() {
    t =
        new Thread() {
          public void run() {
            long time = System.currentTimeMillis();
            long timeNow = System.currentTimeMillis();

            while ((time + 1000) > timeNow) {
              timeNow = System.currentTimeMillis();
              counterN = (int) (1000 - (timeNow - time)) / 100;
            }

            countdownF = false;
            startTime = System.currentTimeMillis();
          }
        };
    if (countdownF) {
      t.start();
    } else {
      t = null;
    }
  }
示例#2
0
  private void animate() {
    r =
        new Thread() {
          public void run() {
            while (true) {
              if (!countdownF) {
                countdown();

                if (!onePlayerAlive) {
                  if (highscore < score) {
                    highscore = score;
                    highscoreL.setText(String.valueOf(highscore));
                  }
                  if (musicCB.isSelected()) {
                    mp3.stop();
                  }
                  break;
                }

                timeElapse = 1 + System.currentTimeMillis() - startTime;
                programLoopCounter++;
                if (programLoopCounter % 100 == 0) {
                  float loopPerSec = (float) programLoopCounter / timeElapse;
                  programSpeedAdjust = (0.3f) / loopPerSec;
                }

                if ((timeElapse > timeCircle) && (ballN < 20)) {
                  timeCircle = timeElapse + timeDifficulty1;
                  ballN++;
                  distance++;
                  spawnIncrease = true;
                }

                score = (int) timeElapse * multiplier;

                if (timeElapse > timeLast) {
                  level++;
                  levelSetup();
                }

                if (timeElapse > timeCircleSwitch) {
                  timeCircleSwitch = timeElapse + 10000;
                  deleteIf(
                      new EnemyPredicate() {
                        public boolean satisfiedBy(Enemy e) {
                          return e.getClass().equals(EnemyTypes.Circle.class);
                        }
                      });
                  if (iter++ % 2 == 0) {
                    spawnMonsters();
                  }
                  ballN = 1;
                  distance = defaultDistance;
                  circular = !circular;
                }

                deleteIf(
                    new EnemyPredicate() {
                      public boolean satisfiedBy(Enemy e) {
                        return e.getClass().equals(EnemyTypes.Shrapnel.class)
                            && (((EnemyTypes.Shrapnel) e).getBounces() > 1);
                      }
                    });

                deleteIf(
                    new EnemyPredicate() {
                      public boolean satisfiedBy(Enemy e) {
                        return e.getClass().equals(EnemyTypes.Bomb.class)
                            && (((EnemyTypes.Bomb) e).isMortal());
                      }
                    });

                movePlayers();
              }

              try {
                SwingUtilities.invokeAndWait(
                    new Runnable() {
                      public void run() {
                        repaint();
                      }
                    });
              } catch (Exception e) {
              }
            }
            back.setVisible(true);
            setCursor(Cursor.getDefaultCursor());
          }
        };
    r.start();
  }