Exemplo n.º 1
0
  /**
   * This method is called on each iteration of the game update loop. It handles the update logic of
   * the game world.
   *
   * @param tpf Time per frame. The time (in seconds) since the last update.
   */
  @Override
  public void simpleUpdate(float tpf) {
    // Do the things that need to be done once... this really shouldn't be here but it needs to
    // happen after the app starts ... -_-
    if (!done) {
      // Disable zoom on mouse wheel scroll
      inputManager.deleteMapping("FLYCAM_ZoomIn");
      inputManager.deleteMapping("FLYCAM_ZoomOut");
      done = true;
    }
    // Check if 'skip forward' has been requested
    if (TimeManipulationActionHandler.getSkipRequested()) {
      this.batchUpdate(TimeManipulationActionHandler.getSkipRequestedSeconds());
      TimeManipulationActionHandler.resetSkipRequested();
    }

    // Multiply the time since last frame by the current game speed to determine how much game time
    // has passed
    float gameSpeed = TimeManipulationActionHandler.getCurrentSpeed();
    tpf *= gameSpeed;
    // If the current speed is less than the default speed run update once
    if (gameSpeed < 1) {
      customUpdate(tpf);
    } else {
      /* For all other values update 'game speed' times.
       * For example: if the time since the last frame is 1 second and the
       * current speed is 5.25 then we will run update 5 times with a tpf
       * value of 1.05 on each of those 5 updates. That will result in a
       * total game time jump of 5.25 seconds.
       * (1 second real time passed * 5.25 speed modifier) = 5.25 seconds.
       *
       * Using this method allows us 'limitless' speed possibilities while
       * ensuring we keep the same level of granularity in our time jumps.
       *
       * ie: using the above example again. If 5 seconds passes between each
       * update the fish have 5 seconds to swim around without being checked
       * by the AI and without being rendered to the display.
       */
      for (int i = 0; i < (int) gameSpeed; i++) {
        customUpdate(tpf / gameSpeed); // Update @ the normal tpf (int)gameSpeed # times
      }
      // Update @ normal tpf * (int)gameSpeed 1 more time
      customUpdate(tpf - ((int) gameSpeed * tpf / gameSpeed));
    }
    // Update the GUI's clock display with the current game time
    PipeToGUI.setGameClock(TimeManipulationActionHandler.getGameTime());
  }
Exemplo n.º 2
0
 /**
  * This method contains the update logic for the game.
  *
  * @param tpf Time in between each update.
  */
 private void customUpdate(float tpf) {
   // Check if pause has been requested
   if (PauseActionHandler
       .getPaused()) { // Game is paused, so only update things that should be updated while game
                       // is paused. ... 'pause menu animation' ... duno
   } else { // Game is not paused, so update things that should only be updated while the game is
            // not paused, like the game clock
     // Increment the game time
     TimeManipulationActionHandler.incrementGameTime(tpf);
   }
   // Fish update regardless of pause (when game = paused fish don't move but are free to idle
   // animate)
   realAI.update(tpf);
 }