Pre combat Cutscene - UQcsse3200/2024-studio-2 GitHub Wiki

Triggering combat

In PlayerActions class, add a listener to listen to the trigger to start combat

entity.getEvents().addListener("startCombat", this::startCombat);

which calls this method which will goes into the pre-combat cutscene

  public void startCombat(Entity enemy) {
    // Stop player movement
    stopWalking();
    // Goes into the pre-combat cutscene
    game.addPreCombatCutsceneScreen(player, enemy);
  }

the screen will go transitioned into the screen from PreCombatCutsceneScreen class, which after 3 seconds will transition into to the combat screen.

public class PreCombatCutsceneScreen extends ResizableScreen {
    private static final float CUTSCENE_DURATION = 3.0f; // Cutscene lasts for 3 seconds
    private float timeElapsed = 0;
    private boolean transition;
    ...

    @Override
    public void render(float delta) {
      if (!isPaused) {
        physicsEngine.update();
        ServiceLocator.getEntityService().update();
        renderer.render();

        timeElapsed += delta;
        if (timeElapsed >= CUTSCENE_DURATION && !transition) {
          transition = true;
          logger.info("Cutscene finished, transitioning to combat screen");

          // Stop the cutscene music before transitioning
          AudioManager.stopMusic();

          game.setScreen(new CombatScreen(game, oldScreen, oldScreenServices, player, enemy));
        }
      }
    }

    private void createUI() {
        // animate the cutscene
    }
    ...
}

The cutscene shows an animation of the Boss NPC sprite, with its name sliding from the sides of the screen.

For Land enemy/boss NPCs:

https://github.com/user-attachments/assets/3da206c3-8cc0-4351-a4cd-a009a058dfce

For Underwater enemy/boss NPCs:

https://github.com/user-attachments/assets/331a775d-883a-46a1-a8ac-b66d4bd0a972

For Sky enemy/boss NPCs:

https://github.com/user-attachments/assets/e032f0cb-0a7f-4105-b9e2-f562f062c9f9