Exemplo n.º 1
0
  public void run() {

    long lastTime = System.nanoTime();
    long timer = System.currentTimeMillis();
    final double ns = 1000000000.0 / 60.0;
    double delta = 0;
    int frames = 0;
    int updates = 0;
    //		setFocusable(true);
    requestFocus();

    while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      while (delta >= 1) {
        update();
        updates++;
        delta--;
      }
      // Renderiza tudo na tela
      render();
      // Calcula FPS
      frames++;

      if ((System.currentTimeMillis() - timer) > 1000) {
        timer += 1000;
        // T�tulo do jogo
        frame.setTitle(title + "  |  " + updates + " ups / " + frames + " fps ");
        updates = 0;
        frames = 0;
      }
    }
    stop();
  }
Exemplo n.º 2
0
  public void checkInput(long elapsedTime) {
    if (exit.isPressed()) {
      stop();
    }

    // Mouse Scrolling Implemented Here.
    if (inputManager.getMouseX() == 0) {
      renderer.setRenderCenterX(renderer.getRenderCenterX() + 5);
    }

    // More Mouse Scrolling
    if (inputManager.getMouseX() == wm.getWidth() - 1) {
      renderer.setRenderCenterX(renderer.getRenderCenterX() - 5);
    }

    // And Some More.
    if (inputManager.getMouseY() == 0) {
      renderer.setRenderCenterY(renderer.getRenderCenterY() + 5);
      ;
    }

    // And Finally, The Last Mouse Scroll.
    if (inputManager.getMouseY() == wm.getHeight() - 1) {
      renderer.setRenderCenterY(renderer.getRenderCenterY() - 5);
      ;
    }

    // Keyboard Scrolling.
    if (scrollMapLeft.isPressed()) {
      renderer.setRenderCenterX(renderer.getRenderCenterX() + WorldMapRenderer.tilesToPixels(3));
    }

    if (scrollMapRight.isPressed()) {
      renderer.setRenderCenterX(renderer.getRenderCenterX() - WorldMapRenderer.tilesToPixels(3));
    }
    if (scrollMapUp.isPressed()) {
      renderer.setRenderCenterY(renderer.getRenderCenterY() + WorldMapRenderer.tilesToPixels(3));
    }

    if (scrollMapDown.isPressed()) {
      renderer.setRenderCenterY(renderer.getRenderCenterY() - WorldMapRenderer.tilesToPixels(3));
    }
    // End of Keyboard Scrolling.
    // More Actions to Go Here.
  }