Ejemplo n.º 1
0
  public void update(float delta) {
    if (levels.get(currentLevel - 1).isWon == true) {
      if (currentLevel >= levels.size()) {
        Gdx.app.exit();
      }
      gravBot.getBody().setTransform(.16f, 0, 0);
      gravBot.getBody().setLinearVelocity(new Vector2(0, 0));
      gravBot.getBody().setAngularVelocity(0);
      destroyLevel();
      currentLevel++;
      startLevel(currentLevel);
    }

    gameWorldPhysics.step(delta, 3, 3);
    gravBot.update(delta);
    for (Obstacle obstacles : obs) {
      obstacles.update(delta);
    }
    clampToScreen();
    runTime += delta;
  }
Ejemplo n.º 2
0
  // Clamps gravBot to screen bounds
  public void clampToScreen() {
    Vector2 gBVec = gravBot.getPosition();
    float width = gravBot.getWidth();
    float height = gravBot.getHeight();

    float screenWidth = Gdx.graphics.getWidth();
    float screenHeight = Gdx.graphics.getHeight();
    float gameWidth = 132;
    float gameHeight = screenHeight / (screenWidth / gameWidth);

    if (gBVec.x < (width / (PPM * 2))) {
      gravBot.getBody().setTransform(width / (PPM * 2), gBVec.y, 0);
      gravBot.getBody().setLinearVelocity(new Vector2(0, 0));
      gravBot.getBody().setAngularVelocity(0);
    }
    if (gBVec.x > (gameWidth - (width / 2)) / PPM) {
      gravBot.getBody().setTransform((gameWidth - (width / 2)) / PPM, gBVec.y, 0);
      gravBot.getBody().setLinearVelocity(new Vector2(0, 0));
      gravBot.getBody().setAngularVelocity(0);
    }
    if (gBVec.y < (height / (PPM * 2))) {
      gravBot.getBody().setTransform(gBVec.x, height / (PPM * 2), 0);
      gravBot.getBody().setLinearVelocity(new Vector2(0, 0));
      gravBot.getBody().setAngularVelocity(0);
    }
    if (gBVec.y > (gameHeight - (height / 2)) / PPM) {
      gravBot.getBody().setTransform(gBVec.x, (gameHeight - (height / 2)) / PPM, 0);
      gravBot.getBody().setLinearVelocity(new Vector2(0, 0));
      gravBot.getBody().setAngularVelocity(0);
    }
  }