Sprint 3: Friendly NPCs - UQdeco2800/2021-studio-6 GitHub Wiki

Summary

Non Player Characters that the player can interact with for various benefits and story snippets. To interact with the NPC, the user will be able to go up to an NPC and press the E key. When interacting, the NPC will speak to the player using the dialogue box feature within the game. Friendly NPCs have been created at the following locations:

  • The start of level 1 to help the player understand how to play the game (like a tutorial)
  • An NPC near the end of the first level
  • A recurring NPC in the first safehouse
  • An NPC at the start of the second level
  • A recurring NPC at the start of level 3

Justification

We believe that adding NPCs during that main gameplay will:

  • Create a more realistic and immersive world
  • Give clarity of the game objective
  • Give additional back story to help the user emotionally connect

Create a more realistic and immersive world

Currently the gameplay starts with a prologue and finishes with an epilogue, however there are no story elements in between. We believe that giving the user more options to experience story elements throughout the game will make the user feel that they are in a realistic world within the world we have created. One example of this is having other Firefly NPCs that the user can meet along the way, which reinforces the prologue's statement that many Fireflies have tried to make the journey before the user. We feel that it also breaks immersion if the user enters the safehouse and there are no other fireflies inside, so having NPCs within the safehouse will help keep the world realistic.

Give clarity of the game objective

From the user testing in sprint 2, users seem to mostly understand the game objective but were confused about some elements. With adding multiple NPCs for the player to talk to, the NPCs will talk more about what the safe haven might be, why it is urgent to get there, who the shadow crawlers are, and what the safehouses are. We will also include some NPCs at the very start of the game that will give the user tips on how to play, similar to a tutorial.

Give additional back story to help the user emotionally connect

We want the user to feel connected to the world's characters/enemies, and therefore giving more story about the town the user has fled from, or the friends people have lost along the way, will help the user connect emotionally with the game.

Class Overview

  • FriendlyNPCFactory.java handles:

    • Creating the animation render component that renders the two animations for each direction.
    • Creating the AI component that adds the wandering movement to the NPC
    • Creates the friendly NPC entity
  • FriendlyNPCTriggerComponent.java handles:

    • Checks to see if the player is in range of the NPC
    • Checks to see if the correct key has been pressed to interact with the NPC
    • Loads and displays the story cutscene relating to the NPC
    • Changes the NPC's direction to face the player when interacting
  • FriendlyNPCAnimationController.java handles:

    • Can set the direction animation that the NPC is facing
    • Continuously checks where the NPC is walking to and sets the direction animation to face that direction
    • Continuously checks whether the NPC is stationary and if so sets the animation to the stationary animation instead of the walking animation
  • SpeechIconComponent.java handles:

    • Renders a speech bubble above the friendly NPC entity
    • Animates the speech bubble to move up and down slightly to attract attention

Unified Modelling Language

Class Diagram

Note: Right click and select open image in new tab to see the full quality image.

This is the UML class diagram that shows the connection between friendly NPC related classes. For simplicity, only the classes immediately connected to the friendly NPC classes are shown in this diagram.

NPC Interaction Sequence Diagram

Note: Right click and select open image in new tab to see the full quality image.

This is the UML sequence diagram that shows the how the player interacts with friendly NPCs. Displaying a story scene has been left out of this sequence diagram and can be found in the StoryManager sequence diagram in the StoryManager wiki.

Adding a New Friendly NPC

Create the NPC assets

  • Create a NPC movement spritesheet and an atlas file that contains the following animated directions (see the player sprite located at assets\images\Player_Sprite for an example):
    • "left"
    • "right"
    • "front"
    • "back"
    • "left-run"
    • "right-run"
    • "front-run"
    • "back-run"
  • Create a dialogue box spritesheet and atlas file that contains the following images (see the current dialogue spritesheet and atlas file at assets\images\dialogue for an example):
    • "dialogue-box-background": the background image for the dialogue box for the NPC
    • "npc-portrait": the portrait that will display for the dialogue box for the NPC

Create the story scene

  • Duplicate a new class in components\story\stories and rename the new class as the new NPC name with with word "Dialogue" appended.
  • Change the "QUOTE" constant to the dialogue that the new NPC will say. Note: each string in the array is a different dialogue screen, where the user will need to press a button to progress to the next dialogue screen.
  • Adjust the "LENGTH" constant to how many dialogue screens have been added to the "QUOTE" constant.

Example of the story scene variables:

  protected static final String[] QUOTE = {"Welcome stranger!", "There is a safe house up ahead!"};
  protected static final String[] PORTRAIT = {"npc-portrait"};
  private static final int LENGTH = 2;
  • Add a new story name to the StoryNames enum (located at game\components\story\StoryNames.java)
  • Within the StoryManager constructor (located at game\components\story\StoryManager.java), link the StoryNames enum to the new story scene class that was created. For example:
scenesConfigs.put(StoryNames.TOWN_GUIDE, new TownGuideDialogue());

Create the NPC

  • Locate the class relating to the area that the new NPC should be spawned into, for example "Level1.java"
  • Create a new method that will spawn in the new NPC. The new method should contain:
    • The grid point location that the NPC should start at, see "pos" variable in the example below.
    • Create the new NPC entity using the FriendlyNPCFactory, see "npc" variable in the example below. The parameters should consist of the story name (use the StoryName enum), the npc movement animation atlas file, and whether the NPC should be wandering or not.
    • Call the spawnEntity method to spawn the new NPC into the level, see the last line of code in the example below.

Example of the spawnNPC method:

  private void spawnNPC() {
    GridPoint2 pos = new GridPoint2(10,2);
    Entity npc = FriendlyNPCFactory.createNewFriendlyNPC(StoryNames.TOWN_GUIDE, npcSampleAtlasFilename, true);
    spawnEntityAt(npc, pos, true, true);
  }

Further Reading