Esempio n. 1
0
  @Override
  public void render(SpriteBatch sb) {
    float leftEdge = player.getPosition().x - cam.viewportWidth / 2 + player.xOffset;
    sb.setProjectionMatrix(cam.combined);
    sb.begin();
    sb.setColor(whiteValue, whiteValue, whiteValue, 1f);
    sb.draw(
        background,
        player.getPosition().x - cam.viewportWidth / 2 + player.xOffset,
        0,
        cam.viewportWidth,
        cam.viewportHeight);
    sb.end();

    Gdx.gl.glEnable(GL20.GL_BLEND);

    sr.setProjectionMatrix(cam.combined);
    sr.begin(ShapeRenderer.ShapeType.Filled);
    // Draw sparkles
    for (int i = 0; i < NUM_SHIMMERS; i++) {
      sr.setColor(
          whiteValue,
          whiteValue,
          whiteValue,
          Math.abs((float) Math.sin(Math.PI * shimmers.get(i).life / Shimmer.MAX_LIFE)));
      sr.circle(
          shimmers.get(i).x + player.getPosition().x - cam.viewportWidth / 2 + player.xOffset,
          shimmers.get(i).y,
          (float) Math.abs(Math.sin(Math.PI * shimmers.get(i).life / Shimmer.MAX_LIFE))
              * shimmers.get(i).size);
    }
    sr.end();
    sb.begin();
    // Draw pause
    sb.draw(
        pauseButton,
        cam.position.x - cam.viewportWidth / 2 + cam.viewportWidth * .05f,
        cam.viewportHeight * .95f - pauseButton.getHeight());

    // Draw balloon
    sb.draw(
        balloon,
        cam.position.x
            - cam.viewportWidth / 2
            + balloonFluctuation.getPosition().x
            - balloon.getWidth() / 2,
        balloonFluctuation.getPosition().y - balloon.getHeight() / 2);

    // Draw text
    if (!textBox.finished) {
      sb.end();
      Gdx.gl.glEnable(GL20.GL_BLEND);
      sr.setProjectionMatrix(cam.combined);
      sr.setAutoShapeType(true);
      sr.begin();
      sr.set(ShapeRenderer.ShapeType.Filled);
      sr.setColor(1f, 1f, 1f, (textBox.alpha > .4f) ? .4f : textBox.alpha);
      // Vert
      sr.rect(
          leftEdge + textBox.x - textBox.width / 2 - textBox.padding / 2,
          textBox.y - textBox.height / 2,
          textBox.width + textBox.padding,
          textBox.height);
      // Horiz
      sr.rect(
          leftEdge + textBox.x - textBox.width / 2,
          textBox.y + textBox.height / 2,
          textBox.width,
          textBox.padding / 2);
      sr.rect(
          leftEdge + textBox.x - textBox.width / 2,
          textBox.y - textBox.height / 2,
          textBox.width,
          -textBox.padding / 2);
      sr.end();
      sb.begin();
      if (textBox.boxOpened) {
        font.setColor(1f, 1f, 1f, textBox.alpha);
        // First line
        font.draw(
            sb,
            textBox.firstLineBuffer,
            (leftEdge + textBox.x - (textBox.width / 2)),
            textBox.y + textBox.height / 2);
        // Second line
        font.draw(
            sb,
            textBox.secondLineBuffer,
            (leftEdge + textBox.x - (textBox.width / 2)),
            textBox.y
                + textBox.height / 2
                - font.getBounds(sceneText.get(textCount).get(0)).height * 1.5f);
      }
    }

    // clouds
    sb.setColor(whiteValue, whiteValue, whiteValue, .75f);
    sb.draw(cloud, clouds.get(0).getPosition().x, clouds.get(0).getPosition().y);
    sb.draw(cloud, clouds.get(1).getPosition().x, clouds.get(1).getPosition().y);

    // draw note
    sb.setColor(whiteValue, whiteValue * (230f / 255f), whiteValue, 1f);
    sb.draw(
        noteAnim.getFrame(),
        note.getPosition().x,
        note.getPosition().y,
        noteAnim.getFrame().getRegionWidth() / 2,
        noteAnim.getFrame().getRegionHeight() / 2,
        noteAnim.getFrame().getRegionWidth(),
        noteAnim.getFrame().getRegionHeight(),
        noteScale,
        noteScale,
        noteRotation);

    sb.setColor(whiteValue, whiteValue, whiteValue, 1f);
    // Draw player
    sb.draw(
        planeRegion,
        player.getPosition().x,
        player.getPosition().y,
        planeRegion.getRegionWidth() / 2,
        planeRegion.getRegionHeight() / 2,
        player.getPlane().getWidth() * .75f,
        player.getPlane().getHeight() * .75f,
        1,
        1,
        player.rotation);

    sb.setColor(whiteValue, whiteValue, whiteValue, 1f);

    // draw brush
    for (FluctuatingObject f : brushmoving) {
      sb.draw(brush, f.getPosition().x, f.getPosition().y);
    }

    sb.end();
    // HUD
    Matrix4 uiMatrix = cam.combined.cpy();
    uiMatrix.setToOrtho2D(0, 0, OwlCityTribute.WIDTH, OwlCityTribute.HEIGHT);

    sb.setProjectionMatrix(uiMatrix);
    sb.begin();
    sb.draw(vignette, 0, 0, cam.viewportWidth, cam.viewportHeight);
    sb.end();
    sr.begin(ShapeRenderer.ShapeType.Filled);
    Gdx.gl.glEnable(GL20.GL_BLEND);

    sr.setColor(1f, 1f, 1f, whiteOverlay);
    sr.setProjectionMatrix(cam.combined);
    sr.rect(leftEdge, 0, cam.viewportWidth, cam.viewportHeight);
    sr.end();
  }
Esempio n. 2
0
  @Override
  public void update(float dt) {
    if (!paused) {
      handleInput();
      if (!readyToFadeWhite) player.update(dt); // So player can be controlled upward from Sky
      else {
        // Lift player
        whiteOverlay += .3f * dt;
        player.getVelocity().add(0, -player.gravity / 2);
        player.getVelocity().scl(dt);
        player.getPosition().add(player.movement * dt, player.getVelocity().y);
        player.getVelocity().scl(1 / dt);
        float temp =
            player.normalize(
                -450, 200, (float) -Math.PI / 4f, (float) Math.PI / 4f, player.getVelocity().y);
        player.rotation = 25 * (float) Math.sin(temp);
        if (whiteOverlay > 1f) {
          dispose();
          Preferences p = Gdx.app.getPreferences(OwlCityTribute.GAME_PREFS);
          p.putInteger("level", 5);
          if (p.getInteger("maxlevel") < 5) {
            p.putInteger("maxlevel", 5);
          }
          p.flush();
          gsm.currentState = GameStateManager.SKY;
          this.gsm.setState(new Sky(this.gsm));
        }
      }
      fallen = player.getPosition().y == -OwlCityTribute.HEIGHT * .1f;

      if (!loss && fallen) {
        loss = true;
        gsm.push(new UponLoss(gsm));
      }

      note.update(dt);
      noteAnim.update(dt);
      noteRotation += 100f * dt;
      if (noteRotation > 360) noteRotation = 0;

      balloonFluctuation.update(dt);

      cam.position.x = player.getPosition().x + player.xOffset;
      float leftEdge = player.getPosition().x - (cam.viewportWidth / 2) + player.xOffset;

      // Check if note is hit
      if (!shrinking
          && Math.sqrt(
                  Math.pow(
                          (player.getPosition().x + player.getPlane().getWidth() * .75f)
                              - note.getPosition().x,
                          2)
                      + Math.pow(
                          (player.getPosition().y + (player.getPlane().getHeight() * .75f) / 2)
                              - (note.getPosition().y + noteAnim.getFrame().getRegionHeight() / 2),
                          2))
              < 40) {
        // Open textbox
        textCount++;
        textBox.prepare(
            sceneText.get(textCount).get(0),
            (sceneText.get(textCount).size() == 1) ? "" : sceneText.get(textCount).get(1),
            .1f);
        boxInitialized = true;

        // Set bounds
        int w = (int) font.getBounds(sceneText.get(textCount).get(0)).width;
        // int h = (int)(font.getBounds(sceneText.get(textCount).get(0)).height*2.5);
        int h =
            (int)
                (font.getBounds(sceneText.get(textCount).get(0)).height
                    * sceneText.get(textCount).size()
                    * 1.5);
        textBox.setBounds(
            w,
            h,
            (int) (OwlCityTribute.WIDTH * .65) - w / 2,
            (int) (OwlCityTribute.HEIGHT * .875) - h / 2);
        waiting = true;
        shrinking = true;
      } else if (note.getPosition().x < leftEdge - noteAnim.getFrame().getRegionWidth()
          && !waiting
          && textCount < sceneText.size() - 1
          && player.movement > player.maxMovement * .75) {
        note.getPosition().x = player.getPosition().x + cam.viewportWidth;
        note.setyOffset((int) (Math.random() * 100) + 200);
      }

      if (shrinking) {
        noteScale -= 2.5 * dt;
        if (noteScale < 0) {
          shrinking = false;
          noteScale = 1f;
          note.getPosition().x -= cam.viewportWidth;
        }
      }

      if (textBox.readyToUpdate) {
        if (!textBox.update(dt)) waiting = true;
        else {
          waiting = false;
          if (textCount < sceneText.size() - 1 && player.movement > player.maxMovement * .75) {
            note.getPosition().x = player.getPosition().x + cam.viewportWidth;
            note.setyOffset((int) (Math.random() * 100) + 200);
          }
        }
      }

      if (!fallen && boxInitialized && textCount == sceneText.size() - 1 && textBox.finished) {
        readyToFadeWhite = true;
      }

      // clouds
      for (int i = 0; i < clouds.size; i++) {
        clouds.get(i).update(dt);
        if (clouds.get(i).getPosition().x < leftEdge - cloud.getWidth()) {
          int index = (i == 0) ? clouds.size - 1 : i - 1;
          clouds.get(i).getPosition().x =
              (float) (clouds.get(index).getPosition().x + cam.viewportWidth * .8);
          clouds.get(i).yOffset =
              random.nextInt((int) (OwlCityTribute.HEIGHT * .1f))
                  + (int) (OwlCityTribute.HEIGHT * .75f);
        }
      }

      //        if(readyToFadeBlack){
      //            whiteValue  = (whiteValue > 0) ? whiteValue - .2f*dt : 0f;
      //            if(whiteValue == 0f){
      //                if(player.getPosition().y == -OwlCityTribute.HEIGHT*.1f){
      //                    dispose();
      //                    this.gsm.setState(new Sky(this.gsm));
      //                }
      //            }
      //        }
      // else{
      whiteValue = (whiteValue < 1f) ? whiteValue + .4f * dt : 1f;
      // }

      // Shimmer update
      for (int i = 0; i < NUM_SHIMMERS; i++) {
        shimmers.get(i).update(dt);
      }

      // Check brush
      for (int i = 0; i < brushmoving.size; i++) {
        brushmoving.get(i).MOVEMENT = -(player.movement / 5);
        brushmoving.get(i).update(dt);
        if (brushmoving.get(i).getPosition().x < leftEdge - brush.getWidth() * 1.5) {
          int index = (i == 0) ? brushmoving.size - 1 : i - 1;
          brushmoving.get(i).getPosition().x =
              brushmoving.get(index).getPosition().x + brush.getWidth();
          break;
        }
      }

      cam.update();
    }
  }