// Metodo que devuelve una textura de un Arraylist cada X tiempo (intervalTime).
 private Texture SwapTextureFromArray(
     ArrayList<Texture> list, int startIndex, long startTime, float intervalTime) {
   Texture img = null;
   if (startIndex < list.size()) {
     Music sound = soundsList.get(startIndex);
     if (TimeUtils.timeSinceMillis(startTime) < intervalTime * 1000) {
       img = list.get(startIndex);
       if (startIndex < titlesList.size()) {
         imageTitle.ChangeFontText(titlesList.get(startIndex));
       }
       if (!soundPlayed) {
         System.out.println("Playing music");
         sound.play();
         soundPlayed = true;
       }
     } else {
       if (!sound.isPlaying()) {
         actualImgIndex++;
         beginTime = TimeUtils.millis();
         img = list.get(startIndex);
         imageTitle.ChangeFontText(titlesList.get(startIndex));
         System.out.println("Music finished");
         soundPlayed = false;
       }
     }
   } else {
     img = list.get(texturesList.size() - 1);
   }
   return img;
 }
 @Override
 public void render() {
   Gdx.gl20.glViewport(
       0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight());
   Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
   shader.begin();
   shader.setUniform2fv(
       "u_resolution",
       new float[] {(float) Gdx.graphics.getWidth(), (float) Gdx.graphics.getHeight()},
       0,
       2);
   shader.setUniformf("u_time", TimeUtils.timeSinceMillis(startTime) / 1000f);
   shader.setUniform2fv(
       "u_mousePos",
       new float[] {Gdx.input.getX(), Gdx.graphics.getHeight() - Gdx.input.getY()},
       0,
       2);
   mesh.render(shader, GL20.GL_TRIANGLES);
   shader.end();
 }
Esempio n. 3
0
  private void updateAction(float delta) {
    elapseTime = TimeUtils.timeSinceMillis(caseStartTime);
    if (elapseTime >= caseTotalTime) {
      Gdx.app.log(TAG, "elapseTime >= caseTotalTime");
      gameState = GameState.CaseFail;
      return;
    }
    selectCount = 0;
    sum = 0;
    if (Gdx.input.justTouched()) {
      game.camera.unproject(touchPosition.set(Gdx.input.getX(), Gdx.input.getY(), 0));

      for (int i = 0; i < 4; i++) {
        if (blockBounds[i].contains(touchPosition.x, touchPosition.y)) {
          selected[i] = !selected[i];
        }

        if (selected[i]) {
          selectCount++;
          sum += number[i];
        }
      }
      if (selectCount == 2) {
        if (sum == answer) {
          gameState = GameState.CaseSolved;
        } else {
          gameState = GameState.CaseFail;
        }
      }
    }

    if (gameState == GameState.CaseFail) {
      this.rumble = new Rumble(5f, 0.5f);
      cameraPosition = game.camera.position;
    }
  }