Skip to content

Transition to Combat Screen for Enemy NPCs

Urawee Thani edited this page Sep 12, 2024 · 5 revisions

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 chicken enemy NPCs:

image

For monkey enemy NPCs:

image

For frog enemy NPCs:

image

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);
Clone this wiki locally