Beispiel #1
0
  /**
   * Update the player
   *
   * @param input user input
   * @param enemy person to check for guns
   */
  public void update(S2DInput input, Enemy enemy) {
    if (health <= 0) {
      isDead = true;
    } else {
      if (isDead == true) {
        world.set(spawn.x, spawn.y);
        gun.resetClip();
        isDead = false;
      }

      if (input.getKey(KeyEvent.VK_W)
          || input.getKey(KeyEvent.VK_S)
          || input.getKey(KeyEvent.VK_A)
          || input.getKey(KeyEvent.VK_D)) {
        moving = true;

        boolean[] sides = new boolean[4];
        if (S2DBoundingBox.intersectAA(man.getBoundingBox(), Map.getBounds())) {
          sides = S2DBoundingBox.intersectBA2(man.getBoundingBox(), Map.getBounds(), .20);
        }

        if (input.getKey(KeyEvent.VK_W) && !sides[S2DBoundingBox.TOPBOUND]) {
          world.add(0, -5);
        }
        if (input.getKey(KeyEvent.VK_S) && !sides[S2DBoundingBox.BOTTOMBOUND]) {
          world.add(0, 5);
        }
        if (input.getKey(KeyEvent.VK_A) && !sides[S2DBoundingBox.LEFTBOUND]) {
          world.add(-5, 0);
        }
        if (input.getKey(KeyEvent.VK_D) && !sides[S2DBoundingBox.RIGHTBOUND]) {
          world.add(5, 0);
        }
      } else {
        moving = false;
      }

      double relativeLocX = (double) (input.getMouseLocation().x) - (double) (Const.SCE_WIDTH / 2);
      double relativeLocY = (double) (input.getMouseLocation().y) - (double) (Const.SCE_HEIGHT / 2);
      radians = Math.atan2(relativeLocY, relativeLocX) + Math.PI / 2;

      gun.update(input, enemy);
    }
  }