NPC Class Code Details - UQdeco2800/2022-studio-1 GitHub Wiki
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.
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:
- Ensure the image is placed into the images/npc directory
- Load the sprite using the asset loader:
private static String[] mainMenuTextures = {
...
"images/npcs/npc_texture.png"
...
}
- 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