public gameMain() {

    this.setDoubleBuffered(true);
    this.addKeyListener(new KeyPressListener());
    this.setFocusable(true);
    main = new Thread(this);
    main.start();

    openLevelFile = true;
  }
  public gameMain(String level) {

    this.setDoubleBuffered(true);
    this.addKeyListener(new KeyPressListener());
    this.setFocusable(true);
    main = new Thread(this);
    main.start();

    initLevel = new File(level);

    openLevelFile = false;
  }
  // -- Main Loop
  public void run() {

    // called only once:
    initialize();

    // create me a timer
    Timer t = new Timer();

    // start main loop:
    while (true) {

      if (levelLoaded == true) {

        camera.follow(mario.sprite);

        // act() all actors that are actable:
        int a = 0;
        while (actor[a] != null && actor[a] instanceof Actable) {
          Actable actable = (Actable) actor[a];
          actable.act();
          a++;
        }

        pCoin.fly();

        for (int i = 0; i < numberOfBoxes; i++) {
          try {
            box[i].open();
          } catch (Exception e) {
            System.out.println("ERROR: " + e);
          }
        }
        for (int i = 0; i < numberOfCoins; i++) {
          try {
            coin[i].collect();
          } catch (Exception e) {
            System.out.println("ERROR: " + e);
          }
        }

        // reset mario if fallen off from screen:
        if (mario.sprite.posy > loadedLevel.getHeight() * 16) {
          camera.position = new Point(width / 2, camera.prefHeight + camera.tolerance);
          mario.sprite.setPosition(new Point(gameMain.mario.spawn.x, gameMain.mario.spawn.y));
        }
      }

      try {

        // Draw to panel if not Fullscreen
        if (fullscreen == false) {

          t.start();

          render();
          repaint();

          System.out.println("FPS: " + (int) (((100 / (double) t.stop())) * 2));

        } else {

          t.start();

          long sleeptime = 5 - t.stop();

          // calculate sleep time (max fps)
          if (sleeptime < 0) {
            sleeptime = 0;
          }

          main.sleep(1L + sleeptime);

          fps = (int) (((100 / (double) t.stop())) * 2);

          System.out.println("FPS: " + fps);
        }
      } catch (Exception e) {

      }
    }
  }