Exemple #1
0
  void inputListener() {
    if (keyboard.keyDown(KeyEvent.VK_W)) player.moveDir[1] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_S)) player.moveDir[1] = 1;
    else player.moveDir[1] = 0;

    if (keyboard.keyDown(KeyEvent.VK_A)) player.moveDir[0] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_D)) player.moveDir[0] = 1;
    else player.moveDir[0] = 0;

    if (keyboard.keyDown(KeyEvent.VK_1)) player.SetWeapon(1);
    if (keyboard.keyDown(KeyEvent.VK_2)) player.SetWeapon(2);
    if (keyboard.keyDown(KeyEvent.VK_3)) player.SetWeapon(3);
    if (keyboard.keyDown(KeyEvent.VK_4)) player.SetWeapon(4);
    if (keyboard.keyDown(KeyEvent.VK_5)) player.SetWeapon(5);
    if (keyboard.keyDown(KeyEvent.VK_6)) player.SetWeapon(6);
    if (keyboard.keyDown(KeyEvent.VK_7)) player.SetWeapon(7);
    if (keyboard.keyDown(KeyEvent.VK_8)) player.SetWeapon(8);
    if (keyboard.keyDown(KeyEvent.VK_9)) player.SetWeapon(9);

    if (keyboard.keyDownOnce(KeyEvent.VK_Z)) {
      if (showDebug) showDebug = false;
      else showDebug = true;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F9)) {
      cheated = true;
      player.health = 1000000;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F10)) {
      cheated = true;
      player.unlockWeapon(2, true);
      player.unlockWeapon(3, true);
      player.unlockWeapon(4, true);
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F11)) {
      cheated = true;
      player.upgradeWeapon(1, 1);
      player.upgradeWeapon(2, 1);
      player.upgradeWeapon(3, 1);
      player.upgradeWeapon(4, 1);
    }
    if (keyboard.keyDown(KeyEvent.VK_F12)) {
      cheated = true;
      player.score = (int) (player.score + 1 / delta);
    }

    if (keyboard.keyDownOnce(KeyEvent.VK_MINUS)) if (difficulty < 19) difficulty = difficulty + 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_BACK_SLASH))
      if (difficulty > 1) difficulty = difficulty - 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = true;
    if (keyboard.keyDownOnce(KeyEvent.VK_M))
      if (removeMode) removeMode = false;
      else removeMode = true;

    if (mouse.buttonDown(1))
      player.Shoot(mouse.getPosition().getX() - xOffset, mouse.getPosition().getY() - yOffset);
  }
Exemple #2
0
  /**
   * Updates the <code>InputManager</code>. This will query current input devices and send
   * appropriate events to registered listeners.
   *
   * @param tpf Time per frame value.
   */
  public void update(float tpf) {
    frameTPF = tpf;

    // Activate safemode if the TPF value is so small
    // that rounding errors are inevitable
    safeMode = tpf < 0.015f;

    long currentTime = keys.getInputTimeNanos();
    frameDelta = currentTime - lastUpdateTime;

    eventsPermitted = true;

    keys.update();
    mouse.update();
    if (joystick != null) {
      joystick.update();
    }
    if (touch != null) {
      touch.update();
    }

    eventsPermitted = false;

    processQueue();
    invokeUpdateActions();

    lastLastUpdateTime = lastUpdateTime;
    lastUpdateTime = currentTime;
  }
Exemple #3
0
 public void linkBindButtonToInput(Input input, SimpleUri bindId) {
   switch (input.getType()) {
     case KEY:
       linkBindButtonToKey(input.getId(), bindId);
       break;
     case MOUSE_BUTTON:
       MouseInput button = MouseInput.find(input.getType(), input.getId());
       linkBindButtonToMouse(button, bindId);
       break;
     case MOUSE_WHEEL:
       linkBindButtonToMouseWheel(input.getId(), bindId);
       break;
     default:
       break;
   }
 }
Exemple #4
0
  /**
   * Initializes the InputManager.
   *
   * <p>This should only be called internally in {@link Application}.
   *
   * @param mouse
   * @param keys
   * @param joystick
   * @param touch
   * @throws IllegalArgumentException If either mouseInput or keyInput are null.
   */
  public InputManager(MouseInput mouse, KeyInput keys, JoyInput joystick, TouchInput touch) {
    if (keys == null || mouse == null) {
      throw new NullPointerException("Mouse or keyboard cannot be null");
    }

    this.keys = keys;
    this.mouse = mouse;
    this.joystick = joystick;
    this.touch = touch;

    keys.setInputListener(this);
    mouse.setInputListener(this);
    if (joystick != null) {
      joystick.setInputListener(this);
      joysticks = joystick.loadJoysticks(this);
    }
    if (touch != null) {
      touch.setInputListener(this);
    }

    firstTime = keys.getInputTimeNanos();
  }
Exemple #5
0
 /**
  * Set whether the mouse cursor should be visible or not.
  *
  * @param visible whether the mouse cursor should be visible or not.
  */
 public void setCursorVisible(boolean visible) {
   if (mouseVisible != visible) {
     mouseVisible = visible;
     mouse.setCursorVisible(mouseVisible);
   }
 }
Exemple #6
0
 public void setMouseCursor(JmeCursor jmeCursor) {
   mouse.setNativeCursor(jmeCursor);
 }
 /** Updates the stored data used by input devices. */
 public static void updateAllInputs() {
   keyboard.poll();
   mouse.poll();
   window.poll();
 }
 /** Clears the stored data of all input devices. */
 public static void clearAllInputs() {
   keyboard.clear();
   mouse.clear();
   window.clear();
 }
 /**
  * Update the core input system - mouse, keyboard and joystick. Thus all events are handled within
  * this method call.<br>
  * To disable joystick support call {@link JoystickInput#setProvider(String)} with {@link
  * #INPUT_SYSTEM_DUMMY} as parameter proir to creating the display.
  *
  * @see KeyInput#update()
  * @see MouseInput#update()
  * @see JoystickInput#update()
  */
 public static void update() {
   MouseInput.get().update();
   KeyInput.get().update();
   JoystickInput.get().update();
 }
 public void performAction(InputActionEvent evt) {
   localTranslation.x = MouseInput.get().getXDelta() * _speed;
   localTranslation.y = MouseInput.get().getYDelta() * _speed;
   worldTranslation.set(localTranslation);
   hotSpotLocation.set(localTranslation).addLocal(hotSpotOffset);
 }
Exemple #11
0
  private void processMouseInput(float delta) {

    if (!engine.hasFocus()) return;

    Vector2i deltaMouse = mouse.getDelta();
    // process mouse movement x axis
    if (deltaMouse.x != 0) {
      mouseXEvent(deltaMouse, delta);
    }
    // process mouse movement y axis
    if (deltaMouse.y != 0) {
      mouseYEvent(deltaMouse, delta);
    }
    // process mouse clicks
    for (InputAction action : mouse.getInputQueue()) {
      switch (action.getInput().getType()) {
        case MOUSE_BUTTON:
          int id = action.getInput().getId();
          if (id != -1) {
            MouseInput button =
                MouseInput.find(action.getInput().getType(), action.getInput().getId());
            boolean consumed =
                sendMouseEvent(
                    button, action.getState().isDown(), action.getMousePosition(), delta);

            BindableButtonImpl bind = mouseButtonBinds.get(button);
            if (bind != null) {
              bind.updateBindState(
                  action.getInput(),
                  action.getState().isDown(),
                  delta,
                  getInputEntities(),
                  targetSystem.getTarget(),
                  targetSystem.getTargetBlockPosition(),
                  targetSystem.getHitPosition(),
                  targetSystem.getHitNormal(),
                  consumed);
            }
          }
          break;
        case MOUSE_WHEEL:
          int dir = action.getInput().getId();
          if (dir != 0 && action.getTurns() != 0) {
            boolean consumed =
                sendMouseWheelEvent(action.getMousePosition(), dir * action.getTurns(), delta);

            BindableButtonImpl bind = (dir == 1) ? mouseWheelUpBind : mouseWheelDownBind;
            if (bind != null) {
              for (int i = 0; i < action.getTurns(); ++i) {
                bind.updateBindState(
                    action.getInput(),
                    true,
                    delta,
                    getInputEntities(),
                    targetSystem.getTarget(),
                    targetSystem.getTargetBlockPosition(),
                    targetSystem.getHitPosition(),
                    targetSystem.getHitNormal(),
                    consumed);
                bind.updateBindState(
                    action.getInput(),
                    false,
                    delta,
                    getInputEntities(),
                    targetSystem.getTarget(),
                    targetSystem.getTargetBlockPosition(),
                    targetSystem.getHitPosition(),
                    targetSystem.getHitNormal(),
                    consumed);
              }
            }
          }
          break;
        case KEY:
          break;
      }
    }
  }