IntroCutscene - UQcsse3200/2024-studio-3 GitHub Wiki

Introduction

The IntroCutscene class is a specific implementation of the Cutscene class, designed to handle the introductory cutscene for the game. It contains text, assets (such as background images), and logic to manage the flow of the cutscene, including automatic transitions to the next stage after a set duration. The cutscene is managed by tracking in-game time and ensuring that the sequence runs smoothly before moving on to the main game or the next cutscene.

Key Features

  • The class extends Cutscene, meaning it inherits basic functionality for managing text-based cutscenes.
  • The cutscene follows a pre-defined script, moving through different lines of dialogue.
  • A background image is loaded and displayed during the cutscene.
  • After a specified duration, the cutscene automatically triggers the transition to the next scene.

Code Implementation

Fields

  • timeStart: captures the time at which the cutscene begins.
  • duration: specifies how long the cutscene will run before ending (2 seconds in this case).
  • gameTime: This object provides access to the game’s internal clock, allowing the cutscene to keep track of how much time has passed since it started. This is crucial for determining when to end the cutscene.
private GameTime gameTime;
float timeStart = 0;
float duration = 2.0f;

update()

This method is responsible for managing the timing of the cutscene and determining when it ends. It is called on every frame update and checks if the cutscene has exceeded the specified duration.

  • Calculate elapsed time: It calculates how much time has passed since the cutscene started by comparing the current game time with the start time (timeStart).

  • Check if the cutscene should end: If the elapsed time exceeds the duration (in this case, 2 seconds), the method triggers the cutsceneEnded event, signalling that the cutscene has finished and the game should transition to the next phase (e.g., another cutscene or gameplay).

@Override
public void update() {
    float currentTime = gameTime.getTime();
    if ((currentTime - timeStart) > duration) {
        logger.debug("Cutscene finished. Triggering next level/cutscene.");
        entity.getEvents().trigger("cutsceneEnded");
    }
}

nextCutscene()

This method is responsible for transitioning to the next cutscene, if available. In this particular case, since no next cutscene is defined, it simply triggers the cutceneEnded event to indicate that the current cutscene is over and moves on.

@Override
protected void nextCutscene() {
    entity.getEvents().trigger("cutsceneEnded");
}

Opening Bistro Scene

Opening Bistro Scene

Testing

Intro Cutscene Test Plan