CutsceneActions - UQcsse3200/2024-studio-3 GitHub Wiki

Introduction

The CutsceneActions class is responsible for handling player interactions during cutscenes in the game. This component listens for specific key presses, such as the space bar or backspace, to allow the player to either progress to the next level or return to the main menu. It integrates with the game’s input system to trigger appropriate transitions once a cutscene ends.

Key Features

  • Space bar Pressed (Proceed to Next Cutscene/Level): When the space bar is pressed during a cutscene, the game transitions to either the next cutscene or the next level in the game.
  • Backspace Pressed (Exit to Main Menu): Pressing the backspace key allows the player to exit the cutscene and return directly to the main menu.

Code Implementation

create()

This method sets up the input service and registers event listeners for transitioning between cutscenes or exiting the cutscene.

@Override
public void create() {
    entity.getEvents().addListener("cutsceneEnded", this::cutsceneEnded);
    entity.getEvents().addListener("exitCutscene", this::exitCutscene);
    inputService = ServiceLocator.getInputService();
}

update()

This method continuously checks for player input during the cutscene.

  • If the space bar is pressed, it logs the event and calls the cutsceneEnded() method to move to the next scene or level.
  • If the backspace is pressed, it logs the event and calls the exitCutscene() method to transition back to the main menu.
@Override
public void update() {
    if (inputService.keyDown(Input.Keys.SPACE)) {
        logger.debug("Space bar pressed. Moving to next cutscene or level.");
        cutsceneEnded();
    }
    if (inputService.keyDown(Input.Keys.BACKSPACE)) {
        logger.debug("Backspace bar pressed. Moving to the main menu");
        exitCutscene();
    }
}

cutsceneEnded()

This method handles the transition from the current cutscene to either the next cutscene or the main game level. A better transition logic might be required in future iterations, as the comment in the code suggests.

private void cutsceneEnded() {
    logger.debug("Transitioning to next cutscene or game level.");
    game.setScreen(GdxGame.ScreenType.MAIN_GAME);
}

exitCutscene()

This method is responsible for transitioning the game back to the main menu when the player opts to leave the cutscene.

private void exitCutscene() {
    logger.debug("Transitioning to main menu");
    game.setScreen(GdxGame.ScreenType.MAIN_MENU);
}