-
Notifications
You must be signed in to change notification settings - Fork 1
Inventory System
In the design of a game, managing in-game items such as weapons, tools, or consumable efficiently is crucial for a smooth gameplay experience. To achieve this, the project employs several key software design patterns and principles, including interfaces and the factory system.
com.csse3200.game.components.player.inventory.Collectible
Interface
Collectible Interface: The Collectible interface defines the basic properties and behaviors of any item that can be collected by the player. By using an interface, the game ensures that any collectible object, whether it's a weapon, item, or other entity, adheres to a consistent structure and can be managed uniformly within the inventory system.
Why Interfaces? Flexibility: Interfaces allow different types of collectibles (items, melee weapons, ranged weapons) to be treated uniformly, enabling polymorphism. Extensibility: New types of collectibles can be added without modifying existing code, as long as they implement the Collectible interface.
-
Type getType()
: Returns the type of the item, determining how it should be used by the player. Types include 'ITEM', 'MELEE_WEAPON', and 'RANGED_WEAPON'. -
String getName()
: Returns the name of the item. -
Texture getIcon()
: Returns the texture used as the item's icon. -
String getSpecification()
: Provides a string representation of the collectible item that can be parsed by theCollectibleFactory
. -
void pickup(Inventory inventory)
: Allows the entity to pick up the item, applying any associated effects. -
void drop(Inventory inventory)
: Removes the item from the entity's inventory.
Type
Enum: Defines the possible types of collectibles: ITEM
, MELEE_WEAPON
, RANGED_WEAPON
.
com.csse3200.game.components.player.inventory.Inventory
Class**
This class represents the inventory system for the player. It tracks the items the player has collected, including melee and ranged weapons.
-
Inventory(InventoryComponent component)
: Constructs an inventory attached to a specific inventory component. -
Entity getEntity()
: Returns the entity to which this inventory is attached. -
Optional<MeleeWeapon> getMelee()
: Returns the currently held melee weapon. -
void setMelee(MeleeWeapon melee)
: Sets the currently held melee weapon and resets any previous one. -
void resetMelee()
: Resets the melee weapon to the default (empty). -
Optional<RangedWeapon> getRanged()
: Returns the currently held ranged weapon. -
void setRanged(RangedWeapon ranged)
: Sets the currently held ranged weapon and resets any previous one. -
void resetRanged()
: Resets the ranged weapon to the default (empty). -
Array<Collectible> getItems()
: Returns a list of currently collected items. -
void addItem(Collectible item)
: Adds a new item to the inventory and triggers an update event.
com.csse3200.game.components.player.inventory.InventoryComponent
Class
This class represents a component that manages the player's inventory. It uses an Inventory
object to track items and weapons.
-
InventoryComponent()
: Constructs a new, empty inventory component. -
void pickup(Collectible item)
: Adds an item to the inventory by calling itspickup
method. -
void drop(Collectible item)
: Removes an item from the inventory by calling itsdrop
method. -
Inventory getInventory()
: Returns the underlyingInventory
object.
InventoryComponent playerInventoryComponent = new InventoryComponent();
Entity player = new Entity();
player.addComponent(playerInventoryComponent);
Collectible potion = new Item("Health Potion");
playerInventoryComponent.pickup(potion);
This factory class is responsible for creating collectible items and converting them into entities.
-
Collectible create(String specification)
: Creates a collectible item based on a specification string. The specification indicates the type of the item (melee, ranged, or item) and the details of the item. -
Entity createCollectibleEntity(Collectible collectible)
: Converts a collectible item into an entity with components
CollectibleFactory factory = new CollectibleFactory();
// Create a melee weapon collectible
Collectible sword = factory.create("melee:Knife");
// Create a ranged weapon collectible
Collectible bow = factory.create("ranged:shotgun");
// Create a generic item collectible
Collectible potion = factory.create("item:health_potion");
Design Choices
Utilities
Animals
Menus/screens
Character
- Character Animations
- Character's Inventory On Display
- Character's Inventory System
- Character's HealthBar
- Character's Interaction with Items
- Character achievements
- Saving Character
- Player-(and-other-NPC)-invincibility-frames
- Player Factory
- Scoring System
- Test Plan for Inventory System
- Test Plan for Player's Interaction with Items
- Test Plan for Player's Inventory Display
- Test Plan for Saving Character State
- Test Plan for Scoring System
Map
Weapon
- Weapon Overview
- Weapon Types
- Weapon Structure
- Weapon Stats Display
- Testing Plan for Weapon Factory
- Testing Plan for Firing Controller Component
- Testing Plan for Position Tracker Component
- Testing Plan for Weapon Animation Controller component
- Testing Plan for Concrete Melee Weapon class
- Testing Plan for Concrete Ranged Weapon class