Beispiel #1
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.
  }
Beispiel #2
0
  public void initInput() {

    // Create Some Game Actions.  These will help when we're checking our input here in just a
    // second.
    exit = new GameAction("exit");
    scrollMapLeft = new GameAction("Scroll Map Left", GameAction.DETECT_INITAL_PRESS_ONLY);
    scrollMapRight = new GameAction("Scroll Map Right", GameAction.DETECT_INITAL_PRESS_ONLY);
    scrollMapUp = new GameAction("Scroll Map UP", GameAction.DETECT_INITAL_PRESS_ONLY);
    scrollMapDown = new GameAction("Scroll Map Down", GameAction.DETECT_INITAL_PRESS_ONLY);

    // create a new InputManager to Handle KeyMapping.
    inputManager = new InputManager(wm.getFullScreenWindow());
    inputManager.mapToKey(scrollMapLeft, KeyEvent.VK_LEFT);
    inputManager.mapToKey(scrollMapRight, KeyEvent.VK_RIGHT);
    inputManager.mapToKey(scrollMapUp, KeyEvent.VK_UP);
    inputManager.mapToKey(scrollMapDown, KeyEvent.VK_DOWN);

    // Finally...No more alt-tabbing + Terminating the program.  This just shuts us down...like now.
    inputManager.mapToKey(exit, KeyEvent.VK_ESCAPE);
  }