Player Inventory and Pickup Items - UQdeco2800/2021-studio-6 GitHub Wiki
Descriptions
Player has an inventory to store items like bandages (used to restore wound state by 1), coins (can be used to buy better weapons in safehouse) and ammo (used to reload gun magazine). These are tracked and updated in the player's inventory and these data variables are displayed via the player's HUD interface for player to be wary of item quantities in inventory. In addition to this inventory, there are items that can be picked up as well in the game. Items that can be picked up are ammo and coins. Player can pick these items and store them in player's inventory (which gets updated via the HUD as well).
Inventory & Item Pickup
As explained, the player's inventory consist of 3 items and is managed in the InventoryComponent.java
. Only player should have this component as only player can actually pick items up and store them.
Implementation of Player Inventory and Item Pickup
Player picks item up by colliding with item fixtures in game world. However, player collides with many other fixtures in game world. Thus, item fixtures are spawned to have behaviors and variables that allows player entity to detect and extract the right data variables that will be used to update specific item (depending on type of items picked up) quantity in inventory. Items that are picked up will be disposed to clearly provide feedback to user that an item has been picked up.
- Inventory: An
InventoryComponent.java
is attached to player entity which stores all relevant data about item quantity and it has all relevant methods to update these variables whenever needed. It also has even triggers which updates player HUD when an item is updated - Pickup Item: A new component called
PlayerPickupComponent.java
is used to give player entity the ability to pick up items. This component is also able to distinguish between different items which updates different item variables in the inventory component. Different fixtures for which player entity collide with is distinguished by checking to ensure that the fixture contains anItemComponent
which is only attached to entities that are items and if that component is found, item ENUMS are used to distinguish the type of items that are picked up by player. - Reusable Items: The only item which is reusable are bandages. As reusable items are meant to affect player's stats in a way and decreases the number of items left in inventory component. A new component called
PlayerReusableComponent.java
is created to mediate the process of updating any effects that are meant to be applied on user by accessing and changing variables in thePlayerCombatStatsComponent.java
and at the same time, update the number of item left in player's inventory by accessingInventoryComponent
.
Design Justification
- With items in placed, player now have the ability to utilize additional items to help survive throughout the game. These are items which will be essential for player's survival and it adds a level of depth in terms of keeping tracking of what is important to the player.
- Items like coins can be used to purchase weapons which allow player to experience a different type of play style as future implementations would involve allowing player to use different weapons to attack enemy which gives users a new experience of using different weapons if they want during different playthroughs.
Team 3 item graphics contributions
-
The ammo was created by creating a vector image of a rock with highlighting, shading and a black outline. This was then pixelated using piskel. It was also decided that there would be two different versions of the ammo one with the black outline for the pickup ammo and one without for the shooting ammo.
-
The coin is deemed to be a valid currency as the story line of the game describes cities continuing to exist in the world. Also it was decided that the colour palette of the coin should include a colour other than orange due to readability. The coin was also made to look older and grimy due to the post apocalyptic nature of the game.
-
User testing items:
-
What would you use this for in a game? Coin - Money, currency, buying power ups Ammo - Throwing, I wouldn’t know to pick it up but maybe to hurt someone
-
What word would you use to describe this image? Coin - money, coin, Ammo - rock, rock, stone
Unified Modeling Language
Sequence Diagram
Design Pattern
- The pickup as well as the reusable components are implemented to adopt the observer design pattern. These have been implemented similarly to how player melee and range attack has been implemented - which in this case, an observer is given the responsibility to always track the player's position and whether or not the player's fixture has collided with any object in the game world. In particular, the collision state of player fixture is paid close attention. This is essential in detecting whether it is time for player to pick up an item and whether player can pick up the item.
- It is logical to adopt such a design pattern as the collision state of player's fixture will need to always be tracked and updated which fits the responsibility of an observer. The observer will track and trigger a chain of events when player collides with any object in the game world. Upon collision, public methods of the object will be called and all relevant data variables are transferred from the object to the player's inventory.
- Upon updating player's inventory, a secondary observer will then trigger an entire new chain of events that updates the player's HUD along with performing additional checks if updating is required. This is ideal as it is simple and straightforward to keep track of particular events that are responsible for triggering specific tasks.