NPC Upgrades - UQcsse3200/2024-studio-3 GitHub Wiki
Introduction
The NPCFactory
class provides methods for creating different types of NPC (Non-Player Character) entities in the game. This documentation covers the creation of a special upgrade NPC (penguin) that interacts with players to offer random upgrades. This NPC appears in the game area, and players can press "U" to access the upgrades menu when the press U hover box is shown.
Purpose
createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upgradesDisplay)
Creates a special upgrade NPC, represented as a penguin, that offers upgrades to the player. The penguin is animated, follows a defined path, and displays a hover box when ready.
createStandard(Vector2 targetPosition)
Creates a standard NPC entity with basic movement and collision components. This serves as a base for other NPC types.
Class Overview
NPCFactory
Class
This class provides factory methods for creating various types of NPCs in the game. It uses different game components, such as physics and AI tasks, to define the behavior and interactions of the created NPCs.
createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upgradesDisplay)
Method: Description: Creates an upgrade NPC that moves to a specified position, displays a hover box when ready, and opens the upgrades menu when U is pressed.
Parameters:
firstPosition
: The initial position where the NPC will be placed in the game.upgradesDisplay
: The display component that will show the upgrades menu when the NPC is clicked.
Behavior:
- The NPC starts moving to the specified position.
- Once it reaches the destination, the hover box becomes visible, indicating itโs ready to interact.
- When U is pressed, the upgrades menu is displayed.
- NPC will be disposed of after interaction.
createStandard(Vector2 targetPosition)
Method: Description: Creates a basic NPC entity with physics and movement capabilities.
Parameters:
targetPosition
: The position the NPC will move towards.
Behavior:
- The NPC moves along a predefined path and interacts with other game entities based on its components.
Key Components:
PhysicsComponent
: Adds properties to the NPC.PhysicsMovementComponent
: Enables movement using physics-based controls.ColliderComponent
: Sets up collision detection with other entities.HitboxComponent
: Defines the hitbox area for interactions.
Spawning the Upgrade NPC
spawnPenguin(UpgradesDisplay upgradesDisplay)
Method: Description: Spawns the upgrade NPC (penguin) in the forest game area at a specified position.
Parameters:
upgradesDisplay
: The display component for showing the upgrades menu.
Behavior:
- The penguin is created using the
createUpgradeNPC
method and spawned at the designated position within the forest game area. - The penguin's position is set based on the
targetPos
vector. - Once spawned, the penguin will move to its initial position and await player interaction.
UML Diagram
Sequential Diagram
Conclusion
The NPCFactory
class provides an efficient way to create and manage special NPCs, like the upgrade-offering penguin. By using predefined components and behaviors, it ensures consistency in NPC interactions and easy integration into different game areas. The spawnPenguin
method can be used to place these NPCs in specific locations, adding variety and interactive opportunities for players within the game.