Ejemplo n.º 1
0
  public void actionPerformed(ActionEvent evt) {

    if (evt.getSource() == timer) {

      player.physics();

      k = 1;
      while (k <= ballCount) {

        ball[k].physics(player.x, player.y, player.size);
        if (ball[k].r < centery - 500 + ball[k].size / 2) {
          health = health - (int) ball[k].size;
          ball[k].r = centery;
          ball[k].t = -Math.PI / 2;
        }
        k++;

        if (grav) {

          k = 1;
          while (k <= ballCount) {
            ball[k].grav();
            k++;
          }

        } else {

          k = 1;
          while (k <= ballCount) {
            ball[k].antiGrav();
            k++;
          }
        }

        k = 1;
        while (k <= ballCount) {

          ball[k].physicsXY();
          k++;
        }

        healthStr = Integer.toString(health) + "%";
        label.setText("Planet Health: " + healthStr);

        repaint();
      }
    }
  }