Transition to Combat Screen for Enemy NPCs - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

The transition to the combat scene involves a cutscene that plays before the player enters the combat phase with an enemy NPC. This cutscene serves to introduce the enemy, display relevant stats, and set the stage for the upcoming battle. The following class, EnemyCutsceneScreen, manages the cutscene and handles the transition to the combat screen.

The implementation and definition for the enemy combat cut scene screen can be found at EnemyCutsceneScreen.

For Land enemy NPCs:

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

For Underwater enemy NPCs:

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

For Sky enemy NPCs:

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

Details

  • Initialization: Sets up the necessary services and initializes the cutscene screen.
  • Rendering: Updates the cutscene and transitions to the combat screen after a specified duration.
  • UI Creation: Creates and animates UI elements, including enemy images and stats labels.
  • Transition Management: Handles the transition from the cutscene to the combat screen.

Setup Transition Screen

        // Load background texture and create Image actor
        Texture backgroundTexture = new Texture("images/transitionBg.jpg");
        Image backgroundImage = new Image(backgroundTexture);

        // Set background image to cover the whole screen
        backgroundImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        // Create black bars
        Texture topBarTexture = new Texture("images/black_bar.png");
        Texture bottomBarTexture = new Texture("images/black_bar.png");

Add more Enemy To game (If needed)

Add new Enemy Type (com/csse3200/game/entities/Entity.java)

  public enum EnemyType {
    KANGAROO,
    CHICKEN,
    MONKEY,
    FROG,
    BEAR
  }

Add Label and Texture For Enemy NPCs

// Select enemy image and name based on enemy type
        switch (enemy.getEnemyType()) {
            case CHICKEN:
                enemyImageTexture = new Texture("images/chicken_idle.png");
                enemyNameLabel = new Label("Chicken", labelStyle);
                break;
            case FROG:
                enemyImageTexture = new Texture("images/frog_idle.png");
                enemyNameLabel = new Label("Frog", labelStyle);
                break;
            case MONKEY:
                enemyImageTexture = new Texture("images/monkey_idle.png");
                enemyNameLabel = new Label("Monkey", labelStyle);
                break;
            case BEAR:
                enemyImageTexture = new Texture("images/bear_idle.png");
                enemyNameLabel = new Label("Bear", labelStyle);
                break;
            default:
                enemyImageTexture = new Texture("images/final_boss_kangaroo_idle.png");
                enemyNameLabel = new Label("Kanga", labelStyle);
                break;
        }

Add more Label for Enemy Stats

// Create labels for stats
        CombatStatsComponent stats = enemy.getComponent(CombatStatsComponent.class);
        Label healthLabel = new Label("Health: " + stats.getHealth() + "/" + stats.getMaxHealth(), labelStyle);
        Label hungerLabel = new Label("Hunger: " + stats.getHunger() + "/" + stats.getMaxHunger(), labelStyle);
        Label strengthLabel = new Label("Strength: " + stats.getStrength(), labelStyle);
        Label defenseLabel = new Label("Defense: " + stats.getDefense(), labelStyle);
        Label speedLabel = new Label("Speed: " + stats.getSpeed(), labelStyle);
        Label experienceLabel = new Label("Experience: " + stats.getExperience() + "/" + stats.getMaxExperience(), labelStyle);

Usage

To use this cutscene screen, instantiate it with the game instance, previous screen, service container, player entity, and enemy entity. It will automatically handle the transition to the combat screen after displaying the cutscene for a set duration.

game.setScreen(new EnemyCutsceneScreen(game, previousScreen, previousScreenServices, playerEntity, enemyEntity));
game.addEnemyCutsceneScreen(player, enemy);

Sequence Diagram

sequenceDiagram
Player        -> GameController          : Player enters combat area
GameController -> CutsceneManager        : Trigger precombat cutscene
CutsceneManager -> Enemy Entity          : Load enemy animations (Idle, Taunt)
CutsceneManager -> CameraController      : Focus on enemy and player
Enemy Entity  -> AnimationRenderComponent : Play taunt animation
CutsceneManager -> DialogueComponent     : Display enemy dialogue
Player        -> CameraController        : Start combat scene
CameraController -> GameController       : Transition to combat phase