Skip to content

NPC Class Code Details

mattbezett edited this page Oct 17, 2022 · 10 revisions

NPC Code Overview

Description

The coding for NPCs is essential for them to function in the game. NPCs spawn in a random location on the island after you have built a certain number of buildings. NPCs can be interacted with and give the player gifts in the form of gold. At night, they despawn, and then respawn again the next morning.

Inspirations

The functionality of NPCs was in part inspired by Terraria, specifically the conditions to spawn NPCs.

Terraria NPCs

For NPCs to spawn, players must build a house of a minimum size with furniture inside. We were inspired by this feature, and therefore implemented a system which requires a minimum number of buildings to be present on the map:

for (int i = NPCNum; i < StructuresNum; i++) {
   spawnNPCharacter();
}

Process

When a new NPC design is created, it needs to implemented into the game. The following steps were followed to accomplish this:

  1. Ensure the image is placed into the images/npc directory
  2. Load the sprite using the asset loader:
private static String[] mainMenuTextures = {
   ...
   "images/npcs/npc_texture.png"
   ...
}
  1. Add the texture to the desired function, e.g. createBaseNPC():
public static Entity createBaseNPC() {
   Entity npc = new Entity()
   ...
   .addComponent(new TextureRenderComponent("images/npcs/npc_texture.png"))
   ...

User Testing

https://github.com/UQdeco2800/2022-studio-1/wiki/NPC-User-Testing

Table of Contents

Home

How to Play

Introduction

Game Features

Main Character

Enemies
The Final Boss

Landscape Objects

Shop
Inventory
Achievements
Camera

Crystal

Infrastructure

Audio

User Interfaces Across All Pages
Juicy UI
User Interfaces Buildings
Guidebook
[Resource Management](Resource-Management)
Map
Day and Night Cycle
Unified Grid System (UGS)
Polishing

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally