Beispiel #1
0
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    game.getInput().getKeyEvents();

    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (event.type == TouchEvent.TOUCH_UP) {
        if (OverlapTester.pointInRectangle(playBounds, touchPoint)) {
          game.setScreen(new GameScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(highscoresBounds, touchPoint)) {
          game.setScreen(new HighscoreScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(helpBounds, touchPoint)) {
          game.setScreen(new HelpScreen(game));
          return;
        }
        if (OverlapTester.pointInRectangle(soundBounds, touchPoint)) {
          Settings.soundEnabled = !Settings.soundEnabled;
        }
      }
    }
  }
  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());
    }
  }
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> events = game.getInput().getTouchEvents();
    int len = events.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = events.get(i);
      if (event.type != TouchEvent.TOUCH_UP) continue;

      guiCam.touchToWorld(touchPoint.set(event.x, event.y));
      if (OverlapTester.pointInRectangle(playBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new GameScreen(game));
      }
      if (OverlapTester.pointInRectangle(settingsBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new SettingsScreen(game));
      }
    }
  }
  private void updatePaused() {
    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(resumeBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        state = GAME_RUNNING;
        return;
      }

      if (OverlapTester.pointInRectangle(quitBounds, touchPoint)) {
        Assets.playSound(Assets.clickSound);
        game.setScreen(new MainMenuScreen(game));
        return;
      }
    }
  }
    @Override
    public void update(float deltaTime) {
      List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
      game.getInput().getKeyEvents();

      int len = touchEvents.size();
      for (int i = 0; i < len; i++) {
        TouchEvent event = touchEvents.get(i);

        camera.touchToWorld(touchPos.set(event.x, event.y));

        cannon.angle = touchPos.sub(cannon.position).angle();

        if (event.type == TouchEvent.TOUCH_UP) {
          float radians = cannon.angle * Vector2.TO_RADIANS;
          float ballSpeed = touchPos.len() * 2;
          ball.position.set(cannon.position);

          ball.velocity.x = FloatMath.cos(radians) * ballSpeed;
          ball.velocity.y = FloatMath.sin(radians) * ballSpeed;

          ball.bounds.lowerLeft.set(ball.position.x - 0.1f, ball.position.y - 0.1f);
        }
      }

      ball.velocity.add(gravity.x * deltaTime, gravity.y * deltaTime);
      ball.position.add(ball.velocity.x * deltaTime, ball.velocity.y * deltaTime);
      ball.bounds.lowerLeft.add(ball.velocity.x * deltaTime, ball.velocity.y * deltaTime);

      List<GameObject> colliders = grid.getPotentialColliders(ball);
      len = colliders.size();

      for (int i = 0; i < len; i++) {
        GameObject collider = colliders.get(i);
        if (OverlapTester.overlapRectangle(ball.bounds, collider.bounds)) {
          grid.removeObject(collider);
          targets.remove(collider);
        }
      }

      if (ball.position.y > 0) {
        camera.position.set(ball.position);
        camera.zoom = 1 + ball.position.y / WORLD_HEIGHT;
      } else {
        camera.position.set(WORLD_WIDTH / 2, WORLD_HEIGHT / 2);
        camera.zoom = 1;
      }
    }
Beispiel #6
0
  @Override
  public void update(float deltaTime) {
    List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
    game.getInput().getKeyEvents();
    int len = touchEvents.size();
    for (int i = 0; i < len; i++) {
      TouchEvent event = touchEvents.get(i);
      touchPoint.set(event.x, event.y);
      guiCam.touchToWorld(touchPoint);

      if (event.type == TouchEvent.TOUCH_UP) {
        if (OverlapTester.pointInRectangle(nextBounds, touchPoint)) {
          Assets.playSound(Assets.clickSound);
          game.setScreen(new HelpScreen5(game));
          return;
        }
      }
    }
  }