コード例 #1
0
ファイル: OptionsScreen.java プロジェクト: agmcleod/ld25
 @Override
 public boolean touchDown(int x, int y, int arg2, int arg3) {
   camera.unproject(mousePos.set(x, y, 0));
   if (backButton.contains(mousePos.x, mousePos.y)) {
     goBack();
   }
   ObjectMap.Entries<String, Rectangle> entries = bindingButtons.entries();
   boolean focusedAnOption = false;
   while (entries.hasNext()) {
     ObjectMap.Entry<String, Rectangle> entry = entries.next();
     Rectangle bounds = entry.value;
     camera.unproject(mousePos.set(x, y, 0));
     if (bounds.contains(mousePos.x, mousePos.y)) {
       this.focused = true;
       focusedAnOption = true;
       this.focusedBox.setY(bounds.y);
       this.focusedBox.setX(bounds.x);
       BitmapFont.TextBounds b = font.getBounds(entry.key);
       this.focusedBox.setHeight(b.height);
       this.focusedBox.setWidth(b.width);
       this.focusedAction = entry.key;
     }
   }
   if (!focusedAnOption) {
     this.focused = false;
   }
   return false;
 }
コード例 #2
0
 @Override
 public boolean touchDown(int screenX, int screenY, int pointer, int button) {
   if (easyRectScaled.contains(screenX, screenY)) {
     Gdx.app.log(LOG, "easy rect hit");
     callback.endScreen(TicTacToeScreen.PLAY, 0);
   } else if (mediumRectScaled.contains(screenX, screenY)) {
     Gdx.app.log(LOG, "medium rect hit");
     callback.endScreen(TicTacToeScreen.PLAY, 1);
   } else if (hardRectScaled.contains(screenX, screenY)) {
     Gdx.app.log(LOG, "hard rect hit");
     callback.endScreen(TicTacToeScreen.PLAY, 2);
   } else if (exitRectScaled.contains(screenX, screenY)) {
     Gdx.app.log(LOG, "exit rect hit");
     callback.endScreen(TicTacToeScreen.EXIT);
   }
   return false;
 }
コード例 #3
0
ファイル: GameScreen.java プロジェクト: idkgi/NerdShooter
  public boolean touchUp(int x, int y, int pointer, int button) {
    if (Gdx.app.getType().equals(Application.ApplicationType.Android)) {
      if (left.contains(x, (y - height) * -1)) {
        controller.leftReleased();
      }

      if (right.contains(x, (y - height) * -1)) {
        controller.rightReleased();
      }

      if (jump.contains(x, (y - height) * -1)) {
        controller.jumpReleased();
      }
      return true;
    }
    return false;
  }
コード例 #4
0
ファイル: AboutScreen.java プロジェクト: Thocro/LD27
  @Override
  public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    screenY = 480 - screenY;

    if (back.contains(screenX, screenY)) {
      Game.changeState(new MainMenu());
    }
    return false;
  }
コード例 #5
0
  public void update() {
    if (Gdx.input.justTouched()) {
      guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));

      if (nextBounds.contains(touchPoint.x, touchPoint.y)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new MainMenuScreen(game));
      }
    }
  }
コード例 #6
0
  public static boolean isTouchingCannon(Vector3 touchPos) {
    Cannon cannon = GameScreen.cannon;

    Vector2 origin = cannon.getPosition();
    origin.x = Utils.convertToWorld(origin.x);
    origin.y = Utils.convertToWorld(origin.y);
    origin.sub(new Vector2(cannon.wrapper.width / 2, cannon.wrapper.height / 2));
    Vector2 end = new Vector2(cannon.wrapper.width, cannon.wrapper.height);
    Rectangle rect = new Rectangle(origin.x, origin.y, end.x, end.y);
    return rect.contains(touchPos.x, touchPos.y);
  }
コード例 #7
0
  /**
   * Obtains the actor at (x,y) with TOLERANCE.
   *
   * <p>Creates a square with size = TOLERANCE and checks:
   *
   * <p>1. if some vertex from the TOLERANCE square is inside an actor bbox 2. if some actor bbox
   * vertex is inside the TOLERANCE square
   */
  public InteractiveActor getInteractiveActorAtWithTolerance(float x, float y, float tolerance) {

    List<SceneLayer> layers = getLayers();

    tmpToleranceRect.x = x - tolerance / 2;
    tmpToleranceRect.y = y - tolerance / 2;
    tmpToleranceRect.width = tolerance;
    tmpToleranceRect.height = tolerance;

    for (SceneLayer layer : layers) {

      if (!layer.isVisible()) continue;

      // Obtain actors in reverse (close to camera)
      for (int l = layer.getActors().size() - 1; l >= 0; l--) {
        BaseActor a = layer.getActors().get(l);

        if (a instanceof InteractiveActor && ((InteractiveActor) a).hasInteraction()) {

          if (a.hit(x, y)
              || a.hit(tmpToleranceRect.x, tmpToleranceRect.y)
              || a.hit(tmpToleranceRect.x + tmpToleranceRect.width, tmpToleranceRect.y)
              || a.hit(tmpToleranceRect.x, tmpToleranceRect.y + tmpToleranceRect.height)
              || a.hit(
                  tmpToleranceRect.x + tmpToleranceRect.width,
                  tmpToleranceRect.y + tmpToleranceRect.height)) return (InteractiveActor) a;

          float[] verts = a.getBBox().getTransformedVertices();
          for (int i = 0; i < verts.length; i += 2) {
            float vx = verts[i];
            float vy = verts[i + 1];

            if (tmpToleranceRect.contains(vx, vy)) return (InteractiveActor) a;
          }
        }
      }
    }

    return null;
  }
コード例 #8
0
 @Override
 public void onMouseMove(float x, float y) {
   if (reorganizePos.contains(x, y)) {
     reorganize.setState(StateTexture.State.SELECTED);
   } else {
     reorganize.setState(StateTexture.State.NORMAL);
   }
   if (newMilitaryPos.contains(x, y)) {
     newMilitary.setState(StateTexture.State.SELECTED);
   } else {
     newMilitary.setState(StateTexture.State.NORMAL);
   }
   if (recruitPos.contains(x, y)) {
     recruit.setState(StateTexture.State.SELECTED);
   } else {
     recruit.setState(StateTexture.State.NORMAL);
   }
   if (trainingPos.contains(x, y)) {
     training.setState(StateTexture.State.SELECTED);
   } else {
     training.setState(StateTexture.State.NORMAL);
   }
   if (mergePos.contains(x, y)) {
     merge.setState(StateTexture.State.SELECTED);
   } else {
     merge.setState(StateTexture.State.NORMAL);
   }
   if (disbandPos.contains(x, y)) {
     disband.setState(StateTexture.State.SELECTED);
   } else {
     disband.setState(StateTexture.State.NORMAL);
   }
   if (upgradePos.contains(x, y)) {
     upgrade.setState(StateTexture.State.SELECTED);
   } else {
     upgrade.setState(StateTexture.State.NORMAL);
   }
 }
コード例 #9
0
ファイル: GameScreen.java プロジェクト: idkgi/NerdShooter
  public boolean touchDragged(int x, int y, int pointer) {
    if (Gdx.app.getType().equals(Application.ApplicationType.Android)) {
      if (controller.isLeftDown()
          && !left.contains(x, (y - height) * -1)
          && controller.leftPointer == pointer) {
        controller.leftReleased();
      }
      if (controller.isRightDown()
          && !right.contains(x, (y - height) * -1)
          && controller.rightPointer == pointer) {
        controller.rightReleased();
      }
      if (controller.isJumpDown()
          && !jump.contains(x, (y - height) * -1)
          && controller.jumpPointer == pointer) {
        controller.jumpReleased();
      }

      if (!controller.isLeftDown()
          && left.contains(x, (y - height) * -1)
          && controller.leftPointer == -1) {
        controller.leftPressed(pointer);
      }

      if (!controller.isRightDown()
          && right.contains(x, (y - height) * -1)
          && controller.rightPointer == -1) {
        controller.rightPressed(pointer);
      }

      if (!controller.isJumpDown()
          && jump.contains(x, (y - height) * -1)
          && controller.jumpPointer == -1) {
        controller.jumpPressed(pointer);
      }
      return true;
    }
    return false;
  }
コード例 #10
0
 @Override
 public void onClick(float x, float y) {
   if (newMilitaryPos.contains(x, y)) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.NEW_MILITARY),
             TabListGameFrame.ListKindType.MILITARY_KIND,
             parent.getCurrentArchitecture(),
             parent.getCurrentArchitecture().getActualCreatableMilitaryKinds(),
             TabListGameFrame.Selection.SINGLE,
             selectedItems -> {
               MilitaryKind kind = (MilitaryKind) selectedItems.get(0);
               parent.getCurrentArchitecture().createMilitary(kind);
               invalidateListPanes();
             });
   } else if (recruitPos.contains(x, y)
       && parent.getCurrentArchitecture().getRecruitableMilitaries().size() > 0) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.RECRUIT_MILITARY),
             TabListGameFrame.ListKindType.PERSON,
             parent.getCurrentArchitecture(),
             parent.getCurrentArchitecture().getPersonsExcludingMayor(),
             TabListGameFrame.Selection.MULTIPLE,
             selectedItems -> {
               for (GameObject i : selectedItems) {
                 Person p = (Person) i;
                 p.setDoingWork(Person.DoingWork.RECRUIT);
               }
               invalidateListPanes();
             });
   } else if (trainingPos.contains(x, y)
       && parent.getCurrentArchitecture().getSelectTrainableMilitaries().size() > 0) {
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.TRAIN_MILITARY),
             TabListGameFrame.ListKindType.PERSON,
             parent.getCurrentArchitecture().getPersonsExcludingMayor(),
             TabListGameFrame.Selection.MULTIPLE,
             selectedItems -> {
               for (GameObject i : selectedItems) {
                 Person p = (Person) i;
                 p.setDoingWork(Person.DoingWork.TRAINING);
               }
               invalidateListPanes();
             });
   } else if (reorganizePos.contains(x, y) && currentMilitary != null) {
     GameObjectList<Person> leaderCandidates =
         new GameObjectList<>(parent.getCurrentArchitecture().getPersonsNotInMilitary());
     leaderCandidates.add(currentMilitary.getLeader());
     parent
         .getScreen()
         .showTabList(
             GlobalStrings.getString(GlobalStrings.Keys.ASSIGN_LEADER),
             TabListGameFrame.ListKindType.PERSON,
             leaderCandidates,
             TabListGameFrame.Selection.SINGLE,
             selectedItems -> {
               currentMilitary.setLeader((Person) selectedItems.get(0));
               parent
                   .getScreen()
                   .showTabList(
                       GlobalStrings.getString(GlobalStrings.Keys.ASSIGN_MILITARY_PERSON),
                       TabListGameFrame.ListKindType.PERSON,
                       parent.getCurrentArchitecture().getPersonsNotInMilitary(),
                       TabListGameFrame.Selection.MULTIPLE,
                       selectedItems1 -> {
                         currentMilitary.setPersons(
                             selectedItems1
                                 .stream()
                                 .map(o -> (Person) o)
                                 .collect(Collectors.toCollection(GameObjectList<Person>::new)));
                         invalidateListPanes();
                       });
             });
   }
 }
コード例 #11
0
ファイル: ScrollPane.java プロジェクト: xYaW/libgdx
 public Actor hit(float x, float y, boolean touchable) {
   if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return null;
   if (scrollX && hScrollBounds.contains(x, y)) return this;
   if (scrollY && vScrollBounds.contains(x, y)) return this;
   return super.hit(x, y, touchable);
 }
コード例 #12
0
  private void processKeys() {
    float x0 = (Gdx.input.getX(0) / (float) Gdx.graphics.getWidth()) * 480;
    float x1 = (Gdx.input.getX(1) / (float) Gdx.graphics.getWidth()) * 480;
    float y0 = 320 - (Gdx.input.getY(0) / (float) Gdx.graphics.getHeight()) * 320;
    float y1 = 320 - (Gdx.input.getY(1) / (float) Gdx.graphics.getHeight()) * 320;
    boolean controlButton =
        (Gdx.input.isTouched(0) && controllButtonRect.contains(x0, y0))
            || (Gdx.input.isTouched(1) && controllButtonRect.contains(x1, y1));
    boolean followButton =
        (Gdx.input.isTouched(0) && followButtonRect.contains(x0, y0))
            || (Gdx.input.isTouched(1) && followButtonRect.contains(x1, y1));

    if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton)
        && state == FOLLOW
        && stateTime > 0.5f) {
      stateTime = 0;
      state = CONTROLLED;
      return;
    }

    if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton)
        && state == CONTROLLED
        && stateTime > 0.5f) {
      stateTime = 0;
      state = FIXED;
      return;
    }

    if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton)
        && state == FIXED
        && stateTime > 0.5f) {
      stateTime = 0;
      state = CONTROLLED;
      return;
    }

    if ((Gdx.input.isKeyPressed(Keys.F) || followButton) && stateTime > 0.5f) {
      stateTime = 0;
      state = FOLLOW;
      return;
    }

    boolean touch0 = Gdx.input.isTouched(0);
    boolean touch1 = Gdx.input.isTouched(1);
    boolean right = (touch0 && (x0 > 80 && x0 < 128)) || (touch1 && (x1 > 80 && x1 < 128));
    boolean down = (touch0 && (y0 < 60)) || (touch1 && (y1 < 60));
    boolean up = (touch0 && (y0 > 80 && x0 < 128)) || (touch1 && (y1 > 80 && y1 < 128));

    if (state == CONTROLLED) {
      if (Gdx.input.isKeyPressed(Keys.A)) {
        accel.x = -ACCELERATION;
      } else if (Gdx.input.isKeyPressed(Keys.D) || right) {
        accel.x = ACCELERATION;
      } else {
        accel.x = 0;
      }

      if (Gdx.input.isKeyPressed(Keys.W) || up) {
        accel.y = ACCELERATION;
      } else if (Gdx.input.isKeyPressed(Keys.S) || down) {
        accel.y = -ACCELERATION;
      } else {
        accel.y = 0;
      }

      if (touch0) {
        if (dpadRect.contains(x0, y0)) {
          float x = (x0 - 64) / 64;
          float y = (y0 - 64) / 64;
          float len = (float) Math.sqrt(x * x + y * y);
          if (len != 0) {
            x /= len;
            y /= len;
          } else {
            x = 0;
            y = 0;
          }
          vel.x = x * MAX_VELOCITY;
          vel.y = y * MAX_VELOCITY;
        } else {
          accel.x = 0;
          accel.y = 0;
        }
      }
    }
  }
コード例 #13
0
ファイル: MouseRegion.java プロジェクト: Whet/AtrophyLibGDX
 @Override
 public boolean isInBounds(int x, int y) {
   return hitbox.contains(x, y);
 }
コード例 #14
0
  private void androidInput() {

    left.width = 75;
    right.width = 75;
    shoot.width = 75;
    jump.width = 75;
    start.width = 75;

    leftSt.width = Game.res.getWidth("small", "Left", 0, Align.bottomLeft, false);
    rightSt.width = Game.res.getWidth("small", "Right", 0, Align.bottomLeft, false);
    shootSt.width = Game.res.getWidth("small", "Shoot", 0, Align.bottomLeft, false);
    ;
    jumpSt.width = Game.res.getWidth("small", "Jump", 0, Align.bottomLeft, false);
    startSt.width = Game.res.getWidth("small", "Start", 0, Align.bottomLeft, false);

    leftSt.height = Game.res.getHeight("small", "Up", 0, Align.bottomLeft, false);
    rightSt.height = Game.res.getHeight("small", "Down", 0, Align.bottomLeft, false);
    shootSt.height = Game.res.getHeight("small", "Shoot", 0, Align.bottomLeft, false);
    jumpSt.height = Game.res.getHeight("small", "Jump", 0, Align.bottomLeft, false);
    startSt.height = Game.res.getHeight("small", "Start", 0, Align.bottomLeft, false);

    left.height = 75;
    right.height = 75;
    shoot.height = 75;
    jump.height = 75;
    start.height = 50;

    start.x = 10;
    start.y = MyConstants.WORLD_HEIGHT - start.height - 10;

    startSt.x = (start.x + (start.width * .5f)) - (startSt.width * .5f);
    startSt.y = (start.y + (start.height * .5f)) + (startSt.height * .5f);

    jump.x = (MyConstants.WOLRD_WIDTH) - (jump.width * .5f) - 10;
    jump.y = (jump.height * .5f) + 10;

    jumpSt.x = jump.x - (jumpSt.width * .5f);
    jumpSt.y = jump.y + (jumpSt.height * .5f);

    shoot.x = (jump.x) - jump.width - 15;
    shoot.y = (shoot.height * .5f) + 10;

    shootSt.x = shoot.x - (shootSt.width * .5f);
    shootSt.y = shoot.y + (shootSt.height * .5f);

    left.x = 10;
    left.y = 10;

    rightSt.x = (right.x + (right.width * .5f)) - (rightSt.width * .5f);
    rightSt.y = (right.y + (right.height * .5f)) + (rightSt.height * .5f);

    right.x = 10 + left.width + 10;
    right.y = 10;

    leftSt.x = (left.x + (left.width * .5f)) - (leftSt.width * .5f);
    leftSt.y = (left.y + (left.height * .5f)) + (leftSt.height * .5f);

    for (int i = 0; i < MyConstants.NUM_TOUCHES; i++) {
      if (Gdx.input.isTouched(i)) {
        if (left.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          lefts[i] = true;
        } else {
          lefts[i] = false;
        }
        if (right.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          rights[i] = true;
        } else {
          rights[i] = false;
        }
        if (shoot.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          shoots[i] = true;
        } else {
          shoots[i] = false;
        }
        if (jump.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          jumps[i] = true;
        } else {
          jumps[i] = false;
        }
        if (start.contains(
            Gdx.input.getX(i) * (MyConstants.WOLRD_WIDTH / Game.SIZE.x),
            MyConstants.WORLD_HEIGHT
                - (Gdx.input.getY(i) * (MyConstants.WORLD_HEIGHT / Game.SIZE.y)))) {
          starts[i] = true;
        } else {
          starts[i] = false;
        }
      } else {
        lefts[i] = false;
        rights[i] = false;
        shoots[i] = false;
        jumps[i] = false;
        starts[i] = false;
      }
    }

    MyInput.setKey(MyConstants.booleanArrayContains(true, lefts), MyInput.LEFT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, rights), MyInput.RIGHT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, shoots), MyInput.SHOOT);
    MyInput.setKey(MyConstants.booleanArrayContains(true, jumps), MyInput.JUMP);
    MyInput.setKey(MyConstants.booleanArrayContains(true, starts), MyInput.START);
  }
コード例 #15
0
 public boolean contains(float x, float y) {
   return visible && bounds.contains(x, y);
 }
コード例 #16
0
 public void buildTouchListeners(
     float screenX, float screenY, ArrayList<FDisplayObject> listeners) {
   if (enabled && visible && screenPos.contains(screenX, screenY)) {
     listeners.add(this);
   }
 }