예제 #1
0
  public void run() {
    long k = 0;
    long paintTimer = 0;
    boolean setTime = true;
    boolean setTimePaint = true;
    finished = false;

    while (exec) {
      try {
        timer++;
        if (timer >= 20000) {
          timer = 0;
        }
        //                if ((timer) % ucTimer == 0) {
        //                    boolean created = false;
        //                    int ir = Math.abs(Ground.rand.nextInt()) % 2 + 1;
        //                    for (int i = 0; i < ir; i++) {
        //                        created = created || handleInhabitantUnitCreation(timer);
        //                    }
        //                    if (!created) {
        //                        System.out.println("No units created");
        //                        timer = ucTimer - 100;
        //                    }
        //                }

        handleBuildingCreation();
        handleUnitCreation();
        um.moveAndFireUnits(timer);
        repaint();
        setTime = true;
        // }

        Thread.sleep(refreshPeriod);
      } catch (InterruptedException ex1) {
        ex1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      } catch (Exception ex2) {
        ex2.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }
    }
    finished = true;
  }
예제 #2
0
  /** Metoda odpowiedzialna za wyswietlenie i animacje trojwymiarowego logo */
  public void displayLogo() {
    try {
      int keys;
      int frames = 0;
      float angle = 10.0f; // kat o jaki obraca sie logo w animacji

      Graphics3D g3d = Graphics3D.getInstance();
      Graphics g = getGraphics();

      // setFullScreenMode(true);

      Thread.sleep(100);

      // zaladowanie obiektu zapisanego w pliku m3g
      Object3D[] objects = Loader.load("/res/blue_logo.m3g");

      scene = (World) objects[0];

      Camera camera = new Camera();
      camera.setPerspective(30.0f, (float) getWidth() / (float) getHeight(), 1.0f, 1000.0f);
      camera.setTranslation(0.0f, 0.0f, 24.0f);
      scene.addChild(camera);
      scene.setActiveCamera(camera);

      scene.getChild(0).preRotate(180.0f, 1.0f, 0.0f, 0.0f);

      keys = getKeyStates();

      while (((keys & FIRE_PRESSED) == 0) && (frames < 36)) { // oczekiwanie na nacisniecie klawisza
        g3d.bindTarget(g);

        scene.getChild(0).preRotate(angle, 0.0f, 0.7f, 1.0f);
        // wyrenderowanie sceny
        g3d.render(scene);
        // zwolnienie kontekstu graficznego
        g3d.releaseTarget();

        flushGraphics();

        Thread.sleep(30); // uspienie watku na 30ms

        keys = getKeyStates();

        frames++;
      }

      while (((getKeyStates() & FIRE_PRESSED) != 0)
          && (frames < 36)) {} // oczekiwanie na zwolnienie przycisku fire

      if ((keys & FIRE_PRESSED)
          == 0) // jesli przycisk nie zostal wcisniety, tylko animacja dobiegla konca
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Praca watku przerysowujacego zawartosc ekranu zostala przerwana!");
      e.printStackTrace();
    } catch (IOException e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Blad podczas wczytywania pliku z zasobow!");
      e.printStackTrace();
    } catch (Exception e) {
      soundPlayer.play(SoundPlayer.ERROR_SOUND);
      System.out.println("Nieznany wyjatek");
      e.printStackTrace();
    }
  }