@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(); } }