Ejemplo n.º 1
0
  private void updateRunning(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      if (event.type != TouchEvent.TOUCH_UP) continue;

      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        state = GAME_PAUSED;
        return;
      }
    }

    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
      lastScore = world.score;
      scoreString = "" + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
      state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      if (lastScore >= Settings.highscores[4]) scoreString = "new highscore: " + lastScore;
      else scoreString = "score: " + lastScore;
      Settings.addScore(lastScore);
      Settings.save(game.getFileIO());
    }
  }
Ejemplo n.º 2
0
  /*
   * Save game score
   * @see com.mygame.framework.Screen#pause()
   */
  @Override
  public void pause() {
    if (state == GameState.Running) state = GameState.Paused;

    if (world.gameOver || world.gameWon) {
      Settings.addScore(world.score);
      Settings.save(game.getFileIO());
    }
  }
Ejemplo n.º 3
0
  /*
   * Durante el periodo de juego en la actualizacion se realizan diferentes comprobaciones
   * y acciones.
   */
  private void updateRunning(float deltaTime) {
    // Capturamos los eventos de usuario con la pantalla
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      // comprobamos que el evento actual es de levantar el dedo.
      if (event.type != TouchEvent.TOUCH_UP) continue;

      // inicializamos el punto de pantalla
      touchPoint.set(event.x, event.y);
      // lo convertimos en coordenadas del juego.
      guiCam.touchToWorld(touchPoint);

      // Comprobamos si la pulsacion ha sido sobre el icono de pausa.
      if (OverlapTester.pointInRectangle(pauseBounds, touchPoint)) {
        // En caso afirmativo cambiamos el estado del juego y reproducimos un sonido.
        Assets.playSound(Assets.clickSound);
        state = GAME_PAUSED;
        return;
      }
      if (OverlapTester.pointInRectangle(moveRightBounds, touchPoint)) {
        world.bob.velocity.x = 10 / 10 * Bob.BOB_MOVE_VELOCITY;
        world.bob.update(deltaTime);
      }
      if (OverlapTester.pointInRectangle(moveLeftBounds, touchPoint)) {
        world.bob.velocity.x = -10 / 10 * Bob.BOB_MOVE_VELOCITY;
        world.bob.update(deltaTime);
      }
    }

    // Actualizamos la puntuacion actual
    world.update(deltaTime, game.getInput().getAccelX());
    if (world.score != lastScore) {
      lastScore = world.score;
      scoreString = "" + lastScore;
    }
    // Comprobamos si hemos llegado al destino, para finalizar el juego.
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
      state = GAME_LEVEL_END;
    }
    // Comprobamos si el estado del mundo es game over, para finalizarel juego.
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      // Si la puntuacion obtenida es mejor a las existintes lo indicamos
      if (lastScore >= Settings.highscores[4]) scoreString = "nuevo record: " + lastScore;
      else scoreString = "puntos: " + lastScore;
      // Actualizamos las puntuaciones y guardamos el fichero de propiedades.
      Settings.addScore(lastScore);
      Settings.save(game.getFileIO());
    }
  }
  private void updateRunning(float deltaTime) {
    if (Gdx.input.justTouched()) {
      guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));

      if (OverlapTester.pointInRectangle(pauseBounds, touchPoint.x, touchPoint.y)) {
        Assets.playSound(Assets.clickSound);
        state = GAME_PAUSED;
        return;
      }
    }

    ApplicationType appType = Gdx.app.getType();

    // should work also with Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer)
    if (appType == ApplicationType.Android || appType == ApplicationType.iOS) {
      world.update(deltaTime, Gdx.input.getAccelerometerX());
    } else {
      float accel = 0;
      if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) accel = 5f;
      if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) accel = -5f;
      world.update(deltaTime, accel);
    }
    if (world.score != lastScore) {
      lastScore = world.score;
      scoreString = "SCORE: " + lastScore;
    }
    if (world.state == World.WORLD_STATE_NEXT_LEVEL) {
      state = GAME_LEVEL_END;
    }
    if (world.state == World.WORLD_STATE_GAME_OVER) {
      state = GAME_OVER;
      if (lastScore >= Settings.highscores[4]) scoreString = "NEW HIGHSCORE: " + lastScore;
      else scoreString = "SCORE: " + lastScore;
      Settings.addScore(lastScore);
      Settings.save();
    }
  }