Repository navigation
Procedural Name Generation
The Procedural Name Generation feature automatically assigns names to NPCs when they are created. Instead of manually defining a name for every NPC, the system combines a randomly selected prefix and suffix to create a formatted name.
Examples of generated names include:
- Grimfang
- Ashbane
- Dreadclaw
- Nightshade
- Bonecrusher
Generated names are stored with the NPC and displayed above the NPC in the game world.
When an NPC is spawned, the following process occurs:
- The
NPCFactorycreates the NPC. -
NameGeneratorselects a random prefix and suffix. - The two parts are combined to create the NPC's name.
- The generated name is stored in a
NameComponent. -
NameDisplayretrieves the name from the NPC. - The name is positioned above the NPC and displayed in the game world.
The feature integrates with the existing NPC and game-area systems.
-
NPCFactorygenerates and assigns names when supported NPCs are created. -
NameComponentstores the generated NPC name. -
LevelGameAreaadds the name display when spawning NPCs. -
NameDisplayuses the existing UI and camera systems to display the name above the NPC. - The existing rendering camera is used to keep the displayed name positioned relative to the NPC.
Names are generated by combining one prefix with one suffix.
- Grim
- Ash
- Dread
- Blood
- Night
- Iron
- Dark
- Bone
- fang
- bane
- claw
- crusher
- walker
- shade
- heart
- skull
The resulting name follows a capitalised prefix followed by a lowercase suffix, such as Grimfang or Ashbane.
NameGenerator uses Java's Random class to independently select a prefix and suffix.
This allows multiple names to be generated without manually defining every possible combination.
Each supported NPC receives a NameComponent containing its generated name when it is created through NPCFactory.
The name is therefore stored directly on the NPC entity and can be accessed by other systems.
NameDisplay is responsible for presenting the generated name to the player.
The display uses the existing Scene2D UI system and projects the NPC's world position onto the screen. The label is positioned above the NPC and follows its location as the game camera moves.
The procedural name generation system includes unit tests covering:
- Name generation
- Generated name formatting
- Invalid random-number-generator input
- Multiple name-generation calls
NameComponent is also tested to ensure that names can be stored and updated correctly and that null or blank names are rejected.
The feature was also manually tested in-game to verify that generated NPC names are visible above NPCs during gameplay.