示例#1
0
  private void gameplay() {
    float y = 0;

    if (missionType == MissionType.VERTICAL) y = AccelerometerManager.getZ() - 3.f;
    else y = AccelerometerManager.getY();
    // Health effects
    if (Math.abs(AccelerometerManager.getX()) > 2 || Math.abs(y) > 2.3) {
      health -= Math.max(Math.abs(AccelerometerManager.getX()), Math.abs(y));
    } else if (health < 100) health++;

    if (health < 0) {
      health = 0;
      missionGivenStatus.setText("You failed! Try again!");
      if (screenState == ScreenState.MAIN || screenState == ScreenState.CLUE)
        setScene(ScreenState.MISSION);
      return;
    }

    mainHealthBar.setValue(health);

    float rotVal = 0;

    if (missionType == MissionType.VERTICAL) rotVal = -(AccelerometerManager.getX() * 4.5f);
    else if (missionType == MissionType.HORIZONTAL) rotVal = -(AccelerometerManager.getY() * 4.5f);
    mainImageTransportation.rotate(rotVal);

    rotVal = Math.abs(rotVal);
    mainImageTransportation
        .getElement()
        .setColorFilter(
            Colour.FromRGB(
                (int) (102 + (rotVal * 2.5f)),
                (int) (123 - (rotVal * 2.5f)),
                (int) (42 - (rotVal))),
            PorterDuff.Mode.MULTIPLY);

    long millis = System.currentTimeMillis() - startTime;
    int seconds = (int) (millis / 1000);
    int minutes = seconds / 60;
    seconds = seconds % 60;
    mainElapsedTime.setText(String.format("Current elapsed \ntime: %d:%02d", minutes, seconds));
  }