コード例 #1
0
ファイル: Stage_Game.java プロジェクト: jDoom/muffintower
  @Override
  public void draw() {
    Gdx.gl.glClearColor(0, 0.2f, 1, 1);
    camera.position.interpolate(
        new Vector3(camera.position.x, camY, 0), 0.1f, Interpolation.pow2Out);
    camera.update();
    batch.setProjectionMatrix(camera.combined);

    if (!pause) world.step(1 / 60f, 8, 3);

    world.getBodies(bodies);
    batch.begin();
    for (i = 0; i < 5; i++) {
      if (backgrounds[i]
          .getBoundingRectangle()
          .overlaps(
              new Rectangle(
                  camera.position.x - camera.viewportWidth / 2,
                  camera.position.y - camera.viewportHeight / 2,
                  camera.viewportWidth,
                  camera.viewportHeight))) {
        backgrounds[i].draw(batch);
      }
    }
    traySprite.draw(batch);
    mpHandler.update(
        Gdx.graphics.getDeltaTime(), true, batch, tap, new Vector2(unprojected.x, unprojected.y));
    for (i = 0; i < bodies.size; i++) {
      scbd = bodies.get(i);
      if (scbd != tmpbd) {
        bodyY.add(scbd.getPosition().y);
      }
      if (scbd.getWorldCenter().y < -2
          || scbd.getWorldCenter().x < -1.3f
          || scbd.getWorldCenter().x > 6.5f) {
        mpHandler.removeFromBody(scbd);
        world.destroyBody(scbd);
        if (!gameOver) {
          if (score > MainClass.highScore) {
            newHighScoreSound.play(MainClass.sound);
          } else {
            gameOverSound.play(MainClass.sound);
          }
          gameOver = true;
          scoreLabel.addAction(new AlphaAction());
          muffinSource.remove();
          pauseButton.remove();
          gameOverDialog.show(this, score);
        }
      }
      if (scbd.getType() == BodyDef.BodyType.DynamicBody) {
        AdjustToBody(muffinSprite, muffinOrigin, scbd, 1.228f, 1);
        muffinSprite.draw(batch);
        if (scbd.isAwake()) {
          if (Math.abs(scbd.getLinearVelocity().len2()) > 10) {
            AdjustToBody(scaredmuffinface, muffinOrigin, scbd, 1.228f, 1);
            scaredmuffinface.draw(batch);
          } else {
            AdjustToBody(awakemuffinface, muffinOrigin, scbd, 1.228f, 1);
            awakemuffinface.draw(batch);
          }
        } else {
          AdjustToBody(normalmuffinface, muffinOrigin, scbd, 1.228f, 1);
          normalmuffinface.draw(batch);
        }
      }
    }
    batch.end();
    camY = 0;
    if (bodyY.size > 5) {
      bodyY.sort();
      for (i = bodyY.size - 3; i < bodyY.size; i++) {
        camY += bodyY.get(i);
      }
      camY /= 3;
      camY += 2;
    }
    if (camY < 4) camY = 4;
    if (drag) {
      tmpbd.setLinearVelocity(
          (unprojected.x - 0.5f - tmpbd.getPosition().x) * 20,
          (unprojected.y - 0.5f - tmpbd.getPosition().y) * 20);
    }
    super.draw();
    bodies.clear();
    bodyY.clear();
  }