Picking Up Potions - UQcsse3200/2023-studio-2 GitHub Wiki
Introduction
Potions often provide various benefits to the player or game characters, such as healing, enhancing abilities, or granting temporary buffs.
Item Pickup Component
The ItemPickupComponent is a crucial part of the game's code responsible for handling the pickup of items like potions. This component is associated with entities that represent items on the game map. When a player or character comes into contact with an item, such as a potion, this component triggers the pickup action.
Constructor
The ItemPickupComponent class has a constructor that takes a parameter called targetLayer. This parameter specifies the collision layer that trigger the pickup when a collision occurs.
create() Method
In the create() method of the ItemPickupComponent, we set up the event listener to handle collisions between the item and other entities:
pickUp(Fixture me, Fixture other) Method
The pickUp method is at the core of the pickup process:
PotionFactory
The PotionFactory class is responsible for creating potion entities in the game. When creating potions, it associates them with various components, including the ItemPickupComponent, to enable the pickup mechanic.
Conclusion
The process of picking up potions is facilitated by the ItemPickupComponent, which is associated with entities representing potions. When a collision occurs between a companion entity and a potion entity, the ItemPickupComponent triggers the pickup action. This action effectively removes the potion from the game world and allows players or characters to benefit from its effects.