Skip to content

Picking Up Potions

saakshigupta2002 edited this page Sep 14, 2023 · 1 revision

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.

Screenshot 2023-09-14 at 1 40 53 PM

create() Method

In the create() method of the ItemPickupComponent, we set up the event listener to handle collisions between the item and other entities: Screenshot 2023-09-14 at 1 41 39 PM

pickUp(Fixture me, Fixture other) Method

The pickUp method is at the core of the pickup process: Screenshot 2023-09-14 at 1 42 49 PM

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. Screenshot 2023-09-14 at 1 44 26 PM

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.

Clone this wiki locally