Skip to content

Player Inventory

connor-golin edited this page Oct 18, 2023 · 23 revisions

Overview

Player Inventory is used to switch between weapons and get details on the equipped weapon. The Player Inventory adds further levels of depth to the game by allowing the player to hold melee, ranged, and buildables in an easily accessible manner - with keyboard buttons 1, 2, and 3 to equip each respectively. Building from Sprint 2, an UpgradeDisplayComponent was created to cater to UX design principles such as ease of use.

Switch Weapons

Weapons can be equipped by simply clicking on a weapon/buildable on the hotbar UI, or by using number keys 1, 2, or 3 to directly switch to a weapon or building hammer.

Update Weapons

Equipped weapons can be switched or upgraded the upgrade tree, which can be accessed through the upgrade tree UI button on screen.

Weapon Details

Stores functional weapon details like weapon type, available ammo and attack cooldown

Key Components

InventoryComponent class:

  • convertSave: Converts the saved map into a map containing the item's slot, and assigned ammo.
  • getSlotTypeMap: Returns a map containing the weapon's slot, and its type
  • getConfigs: Gets weapon configs
  • getEquipped: Gets the equipped weapon's assigned slot
  • setEquipped: Changes active inventory slot to a specific slot
  • replaceSlotWithWeapon: Replaces the specified slot with a given weapon
  • getEquippedWMap: Returns a mapping of item and its respective slot
  • getEquippedWeapons: Returns the current equipped weapons represented in an array
  • changeEquipped: Updates active weapon.
  • getEquippedType: Returns the equipped weapon type
  • getCurrentAmmo: Get the currently equipped weapons current ammo
  • changeEquippedAmmo: Changes the amount of ammo in current weapon slot by change
  • getCurrentAmmoUse: Returns the amount of ammo the currently equipped weapon uses per shot
  • getCurrentMaxAmmo: Returns the amount of max ammo for the current weapon slot
  • getEquippedCooldown: Returns the remaining tick cooldown for the currently equipped weapon slot
  • setEquippedCooldown: Sets the cooldown for the currently equipped weapon slot
  • reloadWeapon: Relaods weapons after 2 seconds
  • getReloading: Return if the weapon is being reloaded

InventoryComponent.InventoryItem class:

Private class to store inventory items

  • InventoryItem: Constructor to create inventory item
  • getItem: Returns weaponType of inventory item
  • changeItem: Updates inventory items weaponType
  • getAmmo: Returns ammo count of inventory item
  • changeAmmo: Updates available ammo for inventory item
  • setMaxAmmo: Sets max ammo capacity of inventory item
  • getMaxAmmo: Returns max ammo capacity of inventory item
  • setAttackCooldown: Sets attack cooldown for inventory item
  • getAttackCooldown: Returns attack cooldown for inventory item
  • decCoolDown: Decreases attack cooldown for inventory item

InventoryDisplayComponent class:

Displays a UI hotbar interface on the current equipped melee, ranged and building hammer.

  • makeTable : Creates a table with three buttons, each button including a label and image specific to the currently equipped item in that slot.
  • updateButtonTableColour : Changes each buttons colour based on whether it is equipped or not - greyed-out for unequipped, else normal.
  • equipEvent : Is a listener function which updates the table if it detects an item change in any slot.

KeyboardPlayerInputComponent class:

  • triggerInventoryEvent: Updates player inventory based on user input; can cycle between weapons or equip a specific weapon.

PlayerActions class:

  • updateInventory: Updates Inventory.

Inventory Display UI

Sprint 3:

Initial design inspiration

Game: Counter Strike: Global Offensive

image

Final Sprint 3 Design

Note: updated as of 29/09/2023

image

Sprint 4:

Unlocked items Hotbar

From the Sprint 3 iteration of the Hotbar, there were found to be a few drawbacks. One of which was that the user had no clear idea of what items they had unlocked. The user was required to visit the upgrade menu to see what they currently have unlocked. Additionally, the user could only swap between items currently equipped in the respective slot. To allow the user to have a seamless experience, we adhered to UX design principles such as ease of visibility. In collaboration with Team 7, we implemented an unlocked items hotbar, which was inspired by popular existing solutions such as Minecraft or Terraria. The Hotbar is located centrally at the bottom of the screen and allows the user to see/switch to their items as soon as they're unlocked. This was implemented with an Observer design pattern, with the concrete observer being the Hotbar UI, and the subject being the Upgrade Tree, which notifies the Hotbar of any changes (new unlocks).

Inspiration; Minecraft hotbar

Sprint 4 Implementation: Ranged weapons equipped

image

Testing plan

PlayerInventory and PlayerInventoryDisplay have been tested in accordance with the Player Inventory Testing Plan

Clone this wiki locally