コード例 #1
0
ファイル: Camera2DTest.java プロジェクト: rjose/threebros
    @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);
        }
      }

      if (ball.velocity.x != 0 || ball.velocity.y != 0) {
        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.overlapRectangles(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;
      }
    }